[map] Call item_t constructor/destructor directly

This commit is contained in:
Behdad Esfahbod 2022-11-17 16:17:37 -07:00
parent 5c88715949
commit ff0bb74895
1 changed files with 14 additions and 20 deletions

View File

@ -71,6 +71,13 @@ struct hb_hashmap_t
uint32_t is_tombstone_ : 1;
V value;
item_t ()
{
hash = 0;
is_used_ = false;
is_tombstone_ = false;
}
bool is_used () const { return is_used_; }
void set_used (bool is_used) { is_used_ = is_used; }
bool is_tombstone () const { return is_tombstone_; }
@ -88,23 +95,6 @@ struct hb_hashmap_t
return minus_1;
};
void construct ()
{
new (this) item_t ();
hash = 0;
is_used_ = false;
is_tombstone_ = false;
}
void destruct ()
{
this->~item_t ();
}
void reconstruct ()
{
destruct ();
construct ();
}
bool operator == (const K &o) { return hb_deref (key) == hb_deref (o); }
bool operator == (const item_t &o) { return *this == o.key; }
hb_pair_t<K, V> get_pair() const { return hb_pair_t<K, V> (key, value); }
@ -149,7 +139,7 @@ struct hb_hashmap_t
if (likely (items)) {
unsigned size = mask + 1;
for (unsigned i = 0; i < size; i++)
items[i].destruct ();
items[i].~item_t ();
hb_free (items);
items = nullptr;
}
@ -179,7 +169,7 @@ struct hb_hashmap_t
return false;
}
for (auto &_ : hb_iter (new_items, new_size))
_.construct ();
new (&_) item_t ();
unsigned int old_size = mask + 1;
item_t *old_items = items;
@ -245,7 +235,11 @@ struct hb_hashmap_t
if (unlikely (!successful)) return;
for (auto &_ : hb_iter (items, mask ? mask + 1 : 0))
_.reconstruct ();
{
/* Reconstruct items. */
_.~item_t ();
new (&_) item_t ();
}
population = occupancy = 0;
}