From 2133aa2407657d0b3b4b73a4951c05ed26d055f2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 9 May 2023 21:06:17 -0600 Subject: [PATCH] [map] Inline code for set() --- src/hb-map.hh | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index 7cf96e424..91ccb196f 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -205,7 +205,20 @@ struct hb_hashmap_t { if (unlikely (!successful)) return false; if (unlikely ((occupancy + occupancy / 2) >= mask && !resize ())) return false; - item_t &item = item_for_hash (key, hash); + + hash &= 0x3FFFFFFF; // We only store lower 30bit of hash + unsigned int i = hash % prime; + while (items[i].is_used ()) + { + if ((hb_is_same (K, hb_codepoint_t) || items[i].hash == hash) && + items[i] == key) + break; + if (items[i].is_tombstone ()) + break; + i = (i + 1) & mask; + } + + item_t &item = items[i]; if (item.is_used ()) { @@ -414,23 +427,6 @@ struct hb_hashmap_t hb_hashmap_t& operator << (const hb_pair_t& v) { set (std::move (v.first), std::move (v.second)); return *this; } - item_t& item_for_hash (const K &key, uint32_t hash) const - { - hash &= 0x3FFFFFFF; // We only store lower 30bit of hash - unsigned int i = hash % prime; - unsigned int tombstone = (unsigned) -1; - while (items[i].is_used ()) - { - if ((hb_is_same (K, hb_codepoint_t) || items[i].hash == hash) && - items[i] == key) - return items[i]; - if (tombstone == (unsigned) -1 && items[i].is_tombstone ()) - tombstone = i; - i = (i + 1) & mask; - } - return items[tombstone == (unsigned) -1 ? i : tombstone]; - } - static unsigned int prime_for (unsigned int shift) { /* Following comment and table copied from glib. */