From cbcdf442c505b1461ef9591d1eedd849237a279b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 26 May 2022 11:20:27 -0600 Subject: [PATCH] [map] Speed up map's own hash() --- src/hb-map.hh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index 11dbe191c..d146b804c 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -100,6 +100,9 @@ struct hb_hashmap_t return key != kinv && value != vinv; } hb_pair_t get_pair() const { return hb_pair_t (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; }