[libcxx-commits] [libcxx] [libc++] Avoid type-punning between __hash_value_type and pair (PR #143501)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 19 01:31:14 PDT 2025


================
@@ -1680,9 +1589,8 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(unordered_map&& __
     : __table_(std::move(__u.__table_), typename __table::allocator_type(__a)) {
   if (__a != __u.get_allocator()) {
     iterator __i = __u.begin();
-    while (__u.size() != 0) {
-      __table_.__emplace_unique(__u.__table_.remove((__i++).__i_)->__get_value().__move());
-    }
+    while (__u.size() != 0)
+      __table_.__insert_multi_from_orphaned_node(std::move(__u.__table_.remove((__i++).__i_)->__get_value()));
----------------
philnik777 wrote:

This is actually correct, since we know for a fact that `__u` contains unique elements here. Still, I've added `__insert_unique_from_orphaned_node` to avoid any performance regressions.

https://github.com/llvm/llvm-project/pull/143501


More information about the libcxx-commits mailing list