From a58bbe5408b76c6b22d3b097649b7eef530c3e13 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 9 May 2023 12:06:35 -0600 Subject: [PATCH] [set] Use better hash --- src/hb-bit-page.hh | 5 +---- src/hb-bit-set.hh | 6 +++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hb-bit-page.hh b/src/hb-bit-page.hh index 9b027ac59..e578d2643 100644 --- a/src/hb-bit-page.hh +++ b/src/hb-bit-page.hh @@ -104,10 +104,7 @@ struct hb_bit_page_t } uint32_t hash () const { - return - + hb_iter (v) - | hb_reduce ([] (uint32_t h, const elt_t &_) { return h * 31 + hb_hash (_); }, (uint32_t) 0u) - ; + return hb_bytes_t ((const char *) &v, sizeof (v)).hash (); } void add (hb_codepoint_t g) { elt (g) |= mask (g); } diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index d290f6114..aad81e25a 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -134,7 +134,11 @@ struct hb_bit_set_t { uint32_t h = 0; for (auto &map : page_map) - h = h * 31 + hb_hash (map.major) + hb_hash (pages[map.index]); + { + auto &page = pages.arrayZ[map.index]; + if (unlikely (page.is_empty ())) continue; + h = h * 31 + hb_hash (map.major) + hb_hash (page); + } return h; }