https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106275

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
  template<typename _Hash>
    struct _Hashtable_hash_traits
    {
      static constexpr std::size_t
      __small_size_threshold() noexcept
      { return std::__is_fast_hash<_Hash>::value ? 0 : 20; }
    };

This new trait determines whether to just do a linear search in a small
container:

  template<typename _Key, typename _Value, typename _Alloc,
           typename _ExtractKey, typename _Equal,
           typename _Hash, typename _RangeHash, typename _Unused,
           typename _RehashPolicy, typename _Traits>
    auto
    _Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
               _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::
    find(const key_type& __k)
    -> iterator
    {
      if (size() <= __small_size_threshold())
        {
          for (auto __it = begin(); __it != end(); ++__it)
            if (this->_M_key_equals(__k, *__it._M_cur))
              return __it;
          return end();
        }

      __hash_code __code = this->_M_hash_code(__k);
      std::size_t __bkt = _M_bucket_index(__code);
      return iterator(_M_find_node(__bkt, __k, __code));
    }

The __is_fast_hash trait is true for std::hash<std::string> but false for your
custom hash function.

Reply via email to