diff --git a/src/hb-array.hh b/src/hb-array.hh index 6b539f2ac..fb5cba18a 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -122,9 +122,13 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> uint32_t hash () const { - uint32_t current = 7; + // FNV-1a hash function + uint32_t current = /*cbf29ce4*/0x84222325; for (auto &v : *this) - current = current * 31 + hb_hash (v); + { + current = current ^ hb_hash (v); + current = current * 16777619; + } return current; } @@ -452,36 +456,50 @@ inline bool hb_array_t::operator == (const hb_array_t inline uint32_t hb_array_t::hash () const { - uint32_t current = 7; + // 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) - current = current * 31 + hb_hash ((uint32_t) ((packed_uint32_t *) &this->arrayZ[i])->v); + { + current = current ^ hb_hash ((uint32_t) ((packed_uint32_t *) &this->arrayZ[i])->v); + current = current * 16777619; + } #endif for (; i < this->length; i++) - current = current * 31 + hb_hash (this->arrayZ[i]); + { + current = current ^ hb_hash (this->arrayZ[i]); + current = current * 16777619; + } return current; } template <> inline uint32_t hb_array_t::hash () const { - uint32_t current = 7; + // 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) - current = current * 31 + hb_hash ((uint32_t) ((packed_uint32_t *) &this->arrayZ[i])->v); + { + current = current ^ hb_hash ((uint32_t) ((packed_uint32_t *) &this->arrayZ[i])->v); + current = current * 16777619; + } #endif for (; i < this->length; i++) - current = current * 31 + hb_hash (this->arrayZ[i]); + { + current = current ^ hb_hash (this->arrayZ[i]); + current = current * 16777619; + } return current; }