[map] Speed up map's own hash()

This commit is contained in:
Behdad Esfahbod 2022-05-26 11:20:27 -06:00
parent de33ef61b7
commit cbcdf442c5
1 changed files with 6 additions and 3 deletions

View File

@ -100,6 +100,9 @@ struct hb_hashmap_t
return key != kinv && value != vinv;
}
hb_pair_t<K, V> get_pair() const { return hb_pair_t<K, V> (key, value); }
uint32_t total_hash () const
{ return (hash * 31) + hb_hash (value); }
};
hb_object_header_t header;
@ -242,9 +245,9 @@ struct hb_hashmap_t
uint32_t hash () const
{
uint32_t h = 0;
/* TODO: Speed-up since we have the hash of the key already in the item. */
for (auto pair : iter ())
h ^= (hb_hash (pair.first) * 31) + hb_hash (pair.second);
for (const auto &item : + hb_array (items, mask ? mask + 1 : 0)
| hb_filter (&item_t::is_real))
h ^= item.total_hash ();
return h;
}