From ff0bb74895ad6b43792cdc2e3add9cbe9c712a15 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 17 Nov 2022 16:17:37 -0700 Subject: [PATCH] [map] Call item_t constructor/destructor directly --- src/hb-map.hh | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index 3aaf3b0b2..7ece3817d 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -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 get_pair() const { return hb_pair_t (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; }