[PATCH][Hashtable 1/6] Code simplification/optimization
Jonathan Wakely
jwakely@redhat.com
Fri Jul 17 09:41:00 GMT 2020
On 17/11/19 21:51 +0100, François Dumont wrote:
>This patch simplifies a number of implementations.
>
>It tries as much as possible to avoid computing hash code. This is
>especially true for the erase implementation in case of multi keys.
>
>
>Â Â Â * include/bits/hashtable_policy.h (_Map_base<>::at): Use
>Â Â Â _Hashtable<>::find.
>(_Hashtable_base<>::_Equal_hash_code<>::_S_node_equals):New.
>Â Â Â (_Hashtable_base<>::_M_node_equals): New, use latter.
>Â Â Â * include/bits/hashtable.h (_Hashtable<>::_M_update_bbegin): New.
>Â Â Â (_Hashtable<>::_M_assign): Use latter.
>Â Â Â (_Hashtable<>::_M_move_assign): Likewise.
>Â Â Â (_Hashtable<>(_Hashtable<>&&)): Likewise.
>Â Â Â (_Hashtable<>(_Hashtable<>&&, const allocator_type&)): Likewise.
>Â Â Â (_Hashtable<>::swap): Likewise.
>Â Â Â (_Hashtable<>::find): Build iterator directly from _M_find_node result.
>Â Â Â (_Hashtable<>::count): Use _Hashtable<>::find.
>Â Â Â (_Hashtable<>::equal_range): Likewise.
>Â Â Â (_Hashtable<>::_M_erase(false_type, const key_type&)): Use
>Â Â Â _M_node_equals.
>
>Tested under Linux x86_64.
OK for master except for one comment ...
>@@ -1457,14 +1466,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> std::swap(_M_element_count, __x._M_element_count);
> std::swap(_M_single_bucket, __x._M_single_bucket);
>
>- // Fix buckets containing the _M_before_begin pointers that can't be
>- // swapped.
>- if (_M_begin())
>- _M_buckets[_M_bucket_index(_M_begin())] = &_M_before_begin;
>-
>- if (__x._M_begin())
>- __x._M_buckets[__x._M_bucket_index(__x._M_begin())]
>- = &__x._M_before_begin;
>+ // Fix bucket containing the _M_before_begin pointer that can't be swap.
"can't be swap" should be "can't be swapped" as it was in the original
comment.
OK with that change, thanks.
>+ _M_update_bbegin();
>+ __x._M_update_bbegin();
> }
>
> template<typename _Key, typename _Value,
More information about the Gcc-patches
mailing list