From ebdeab8baaa0cd7a6d243bb1b2f2604bef167eea Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 7 May 2023 14:18:36 -0600 Subject: [PATCH] [array] Improve hash function Previously all arrays of 0 bytes were getting same hash. --- src/hb-array.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hb-array.hh b/src/hb-array.hh index e82c08153..6b539f2ac 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -122,7 +122,7 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> uint32_t hash () const { - uint32_t current = 0; + uint32_t current = 7; for (auto &v : *this) current = current * 31 + hb_hash (v); return current; @@ -452,7 +452,7 @@ inline bool hb_array_t::operator == (const hb_array_t inline uint32_t hb_array_t::hash () const { - uint32_t current = 0; + uint32_t current = 7; unsigned i = 0; #if defined(__OPTIMIZE__) && !defined(HB_NO_PACKED) && \ @@ -470,7 +470,7 @@ inline uint32_t hb_array_t::hash () const template <> inline uint32_t hb_array_t::hash () const { - uint32_t current = 0; + uint32_t current = 7; unsigned i = 0; #if defined(__OPTIMIZE__) && !defined(HB_NO_PACKED) && \