On 16/02/2025 23:14, Jonathan Wakely wrote:
On Sun, 16 Feb 2025 at 21:15, François Dumont <frs.dum...@gmail.com> wrote:
Hi

A minor simplification.

libstdc++: Simplify _Hashtable::_M_merge_multi

When merging two hashtable instances of the same type we do not need
to go through _M_src_hash_code that also check for identical Hash functor
type.
But that check is very cheap, do we really gain much here?

No runtime gain no, just limit instantiations.


If we're getting rid of _M_src_hash_code in this overload of
_M_merge_multi, should we get rid of it in the other overload too,
since that's the only other place that uses _M_src_hash_code?

Seems complicated, so maybe we can avoid is_same_v and is_empty_v with this smaller patch ?

    libstdc++: [_Hashtable] Avoid is_same_v and is_empty_v instantiations

    There is no need to check for same Hash functor type and this type being stateless
    if there is no hash code cached to reuse.

    libstdc++-v3/ChangeLog:

            * include/bits/hashtable.h (_Hashtable<>::_M_src_hash_code):
            Add __hash_cached::value check.

Let me know if interested.

François
diff --git a/libstdc++-v3/include/bits/hashtable.h 
b/libstdc++-v3/include/bits/hashtable.h
index d6d76a743bb..b17a314a11d 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -1213,6 +1213,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        _M_src_hash_code(const _H2&, const key_type& __k,
                         const __node_value_type& __src_n) const
        {
+         if constexpr (__hash_cached::value)
            if constexpr (std::is_same_v<_H2, _Hash>)
              if constexpr (std::is_empty_v<_Hash>)
                // If the node has a cached hash code, it's OK to use it.

Reply via email to