[map] Speed up operator= for trivial item types

This commit is contained in:
Behdad Esfahbod committed 2025-09-13 17:56:34 -06:00
1 parent 78e5920dcc
commit fd282dcfe7
1 file changed
+10 -2
+10 -2
View File
@@ -47,7 +47,7 @@ struct hb_hashmap_t
hb_hashmap_t () { init (); }
~hb_hashmap_t () { fini (); }
hb_hashmap_t (const hb_hashmap_t& o) : hb_hashmap_t ()
void _copy (const hb_hashmap_t& o)
{
if (unlikely (!o.mask)) return;
@@ -70,8 +70,16 @@ struct hb_hashmap_t
alloc (o.population); hb_copy (o, *this);
}
hb_hashmap_t (const hb_hashmap_t& o) : hb_hashmap_t () { _copy (o); }
hb_hashmap_t& operator= (const hb_hashmap_t& o)
{
reset ();
if (!items) { _copy (o); return *this; }
alloc (o.population); hb_copy (o, *this); return *this;
}
hb_hashmap_t (hb_hashmap_t&& o) noexcept : hb_hashmap_t () { hb_swap (*this, o); }
hb_hashmap_t& operator= (const hb_hashmap_t& o) { reset (); alloc (o.population); hb_copy (o, *this); return *this; }
hb_hashmap_t& operator= (hb_hashmap_t&& o) noexcept { hb_swap (*this, o); return *this; }
hb_hashmap_t (std::initializer_list<hb_pair_t<K, V>> lst) : hb_hashmap_t ()