diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2019-05-16 15:18:50 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2019-05-16 15:18:50 +0100 |
commit | eba20412b43dbb36c57f4235e3a3fff2eb88ba9a (patch) | |
tree | f6aedff73a51e31b3499f8379ab4cc2d539c5ab1 | |
parent | 1f6ea96860f448ba4cc5bf1e7570b6181611328b (diff) | |
download | gcc-eba20412b43dbb36c57f4235e3a3fff2eb88ba9a.zip gcc-eba20412b43dbb36c57f4235e3a3fff2eb88ba9a.tar.gz gcc-eba20412b43dbb36c57f4235e3a3fff2eb88ba9a.tar.bz2 |
Replace _Equal_helper with simpler class template
By defining the new helper inside _Hashtable_base it doesn't need all
the template parameters to be provided, and by making it only
responsible for checking a possibly-cached hash code it only has to do
one thing. The caller can use the equality predicate itself instead of
duplicating that in the helper template.
* include/bits/hashtable_policy.h (_Equal_helper): Remove.
(_Hashtable_base::_Equal_hash_code): Define new class template.
(_Hashtable_base::_M_equals): Use _Equal_hash_code instead of
_Equal_helper.
From-SVN: r271291
-rw-r--r-- | libstdc++-v3/ChangeLog | 5 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/hashtable_policy.h | 54 |
2 files changed, 23 insertions, 36 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index bb947cc..060d92a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,10 @@ 2019-05-16 Jonathan Wakely <jwakely@redhat.com> + * include/bits/hashtable_policy.h (_Equal_helper): Remove. + (_Hashtable_base::_Equal_hash_code): Define new class template. + (_Hashtable_base::_M_equals): Use _Equal_hash_code instead of + _Equal_helper. + * include/bits/hashtable_policy.h (_Hashtable_ebo_helper::_S_get): Replace with _M_get non-static member function. (_Hashtable_ebo_helper::_S_cget): Replace with _M_cget non-static diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h index f7db762..86589e9 100644 --- a/libstdc++-v3/include/bits/hashtable_policy.h +++ b/libstdc++-v3/include/bits/hashtable_policy.h @@ -1403,38 +1403,6 @@ namespace __detail _M_h2() const { return __ebo_h2::_M_cget(); } }; - /** - * Primary class template _Equal_helper. - * - */ - template <typename _Key, typename _Value, typename _ExtractKey, - typename _Equal, typename _HashCodeType, - bool __cache_hash_code> - struct _Equal_helper; - - /// Specialization. - template<typename _Key, typename _Value, typename _ExtractKey, - typename _Equal, typename _HashCodeType> - struct _Equal_helper<_Key, _Value, _ExtractKey, _Equal, _HashCodeType, true> - { - static bool - _S_equals(const _Equal& __eq, const _ExtractKey& __extract, - const _Key& __k, _HashCodeType __c, _Hash_node<_Value, true>* __n) - { return __c == __n->_M_hash_code && __eq(__k, __extract(__n->_M_v())); } - }; - - /// Specialization. - template<typename _Key, typename _Value, typename _ExtractKey, - typename _Equal, typename _HashCodeType> - struct _Equal_helper<_Key, _Value, _ExtractKey, _Equal, _HashCodeType, false> - { - static bool - _S_equals(const _Equal& __eq, const _ExtractKey& __extract, - const _Key& __k, _HashCodeType, _Hash_node<_Value, false>* __n) - { return __eq(__k, __extract(__n->_M_v())); } - }; - - /// Partial specialization used when nodes contain a cached hash code. template<typename _Key, typename _Value, typename _ExtractKey, typename _H1, typename _H2, typename _Hash> @@ -1788,8 +1756,22 @@ namespace __detail iterator>::type; private: using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>; - using _EqualHelper = _Equal_helper<_Key, _Value, _ExtractKey, _Equal, - __hash_code, __hash_cached::value>; + + template<typename _NodeT> + struct _Equal_hash_code + { + static bool + _S_equals(__hash_code, const _NodeT&) + { return true; } + }; + + template<typename _Ptr2> + struct _Equal_hash_code<_Hash_node<_Ptr2, true>> + { + static bool + _S_equals(__hash_code __c, const _Hash_node<_Ptr2, true>& __n) + { return __c == __n._M_hash_code; } + }; protected: _Hashtable_base() = default; @@ -1801,8 +1783,8 @@ namespace __detail bool _M_equals(const _Key& __k, __hash_code __c, __node_type* __n) const { - return _EqualHelper::_S_equals(_M_eq(), this->_M_extract(), - __k, __c, __n); + return _Equal_hash_code<__node_type>::_S_equals(__c, *__n) + && _M_eq()(__k, this->_M_extract()(__n->_M_v())); } void |