[PATCH] Enhance unordered container merge

François Dumont frs.dumont@gmail.com
Mon Nov 15 06:00:19 GMT 2021


On 15/11/21 12:25 am, Jonathan Wakely wrote:
> On Sun, 14 Nov 2021 at 13:31, François Dumont via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
>>       libstdc++: Unordered containers merge re-use hash code.
>>
>>       When merging between 2 unordered containers with same hasher we can
>> re-use
>>       the cached hash code if any.
> Instead of introducing the _ReuseOrComputeHash type, wouldn't it be
> simpler to just overload _M_hash_code?
>
>
>      // Same hash function, use the cached hash code.
>      __hash_code
>      _M_hash_code(const _Hash&,
>          const _Hash_node_value<_Value, true>& __n) const
>      { return __n._M_hash_code; }
>
>    // Compute hash code using a different hash function, _H2
>    template<typename _H2>
>     __hash_code
>     _M_hash_code(const _H2&,
>         const _Hash_node_value<_Value, __cache_hash_code>& __n) const
>     { return this->_M_hash_code(_ExtractKey{}(__n._M_v()); }
>
> The first overload is more specialized, so will be chosen when the
> first argument is the same type as _Hash and the cache_has_code
> boolean is true.

Yes, it is simpler.

Ok to commit ?

François


-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashtable_merge.patch
Type: text/x-patch
Size: 5074 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20211115/f76e38e8/attachment.bin>


More information about the Gcc-patches mailing list