[PATCH] Enhance unordered container merge

Jonathan Wakely jwakely.gcc@gmail.com
Sun Nov 14 23:25:32 GMT 2021


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.


More information about the Gcc-patches mailing list