libstdc++: Unordered containers merge re-use hash code
authorFrançois Dumont <fdumont@gcc.gnu.org>
Mon, 25 Oct 2021 13:59:35 +0000 (15:59 +0200)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Mon, 15 Nov 2021 17:52:07 +0000 (18:52 +0100)
commitd10b863fa3de8b202aadbdef1b012188ab0868d8
tree6f4311493baaa5509b1c2abe64dee5874baa1fe7
parentf861ed8b29a5eb6164d1ddbcfbb6232dddae713f
libstdc++: Unordered containers merge re-use hash code

When merging 2 unordered containers with same hasher we can re-use the hash code from
the cache if any.

Also in the context of the merge operation on multi-container use previous insert iterator as a hint
for the next insert.

libstdc++-v3/ChangeLog:

* include/bits/hashtable_policy.h:
(_Hash_code_base<>::_M_hash_code(const _Hash&, const _Hash_node_value<_Value, true>&)): New.
(_Hash_code_base<>::_M_hash_code<_H2>(const _H2&, const _Hash_node_value<>&)): New.
* include/bits/hashtable.h (_Hashtable<>::_M_merge_unique): Use latter.
(_Hashtable<>::_M_merge_multi): Likewise.
* testsuite/23_containers/unordered_multiset/modifiers/merge.cc (test05): New test.
* testsuite/23_containers/unordered_set/modifiers/merge.cc (test04): New test.
libstdc++-v3/include/bits/hashtable.h
libstdc++-v3/include/bits/hashtable_policy.h
libstdc++-v3/testsuite/23_containers/unordered_multiset/modifiers/merge.cc
libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/merge.cc