From c005e3a2e30eaea700e67907dc816709263b4046 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 8 May 2023 16:33:31 -0600 Subject: [PATCH] [bytes] Simplify hash function Part of https://github.com/harfbuzz/harfbuzz/issues/4227 --- src/hb-array.hh | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/hb-array.hh b/src/hb-array.hh index 1a22e15c0..a7553fc4e 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -458,21 +458,9 @@ inline uint32_t hb_array_t::hash () const { // FNV-1a hash function uint32_t current = /*cbf29ce4*/0x84222325; - unsigned i = 0; - -#if defined(__OPTIMIZE__) && !defined(HB_NO_PACKED) && \ - ((defined(__GNUC__) && __GNUC__ >= 5) || defined(__clang__)) - struct __attribute__((packed)) packed_uint32_t { uint32_t v; }; - for (; i + 4 <= this->length; i += 4) + for (auto &v : *this) { - current = current ^ hb_hash ((uint32_t) ((const packed_uint32_t *) &this->arrayZ[i])->v); - current = current * 16777619; - } -#endif - - for (; i < this->length; i++) - { - current = current ^ hb_hash (this->arrayZ[i]); + current = current ^ v; current = current * 16777619; } return current; @@ -483,21 +471,9 @@ inline uint32_t hb_array_t::hash () const { // FNV-1a hash function uint32_t current = /*cbf29ce4*/0x84222325; - unsigned i = 0; - -#if defined(__OPTIMIZE__) && !defined(HB_NO_PACKED) && \ - ((defined(__GNUC__) && __GNUC__ >= 5) || defined(__clang__)) - struct __attribute__((packed)) packed_uint32_t { uint32_t v; }; - for (; i + 4 <= this->length; i += 4) + for (auto &v : *this) { - current = current ^ hb_hash ((uint32_t) ((const packed_uint32_t *) &this->arrayZ[i])->v); - current = current * 16777619; - } -#endif - - for (; i < this->length; i++) - { - current = current ^ hb_hash (this->arrayZ[i]); + current = current ^ v; current = current * 16777619; } return current;