]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix invalid casts in unordered container merge functions
authorJonathan Wakely <jwakely@redhat.com>
Thu, 14 Nov 2024 14:25:52 +0000 (14:25 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 18 Nov 2024 08:22:27 +0000 (08:22 +0000)
commitdffc37deaddf08bd11208a459496b30021700203
tree35c46e6395c8bf8f8546040afbe1a304c521fdad
parent7b8b96a327f2201531c0a2b32db490532db4aa39
libstdc++: Fix invalid casts in unordered container merge functions

François pointed out that static_cast<__node_ptr>(&_M_before_begin) is
invalid, because _M_before_begin is only a node-base not a node.

Refactor the new merge overloads to only cast when we know we have a
valid node.

He also pointed out some optimizations to allow reusing hash codes that
might be cached in the node. The _M_src_hash_code function already has
the right logic to decide when a cached hash code can be reused by a
different _Hashtable object.

libstdc++-v3/ChangeLog:

* include/bits/hashtable.h (_Hashtable::_M_src_hash_code):
Improve comments.
(_Hashtable::_M_merge_unique(_Hashtable&)): Use pointer_traits
to get before-begin pointer. Only use static_cast on valid
nodes, not the before-begin pointer. Reuse a hash code cached in
the node when possible.
(_Hashtable::_M_merge_multi(_Hashtable&)): Likewise.

Reviewed-by: François Dumont <fdumont@gcc.gnu.org>
libstdc++-v3/include/bits/hashtable.h