[bytes] Simplify hash function

Part of https://github.com/harfbuzz/harfbuzz/issues/4227
pull/4228/head
Behdad Esfahbod 2 years ago
parent 0e02680803
commit c005e3a2e3
  1. 32
      src/hb-array.hh

@ -458,21 +458,9 @@ inline uint32_t hb_array_t<const char>::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)
{
current = current ^ hb_hash ((uint32_t) ((const packed_uint32_t *) &this->arrayZ[i])->v);
current = current * 16777619;
}
#endif
for (; i < this->length; i++)
for (auto &v : *this)
{
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<const unsigned char>::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)
{
current = current ^ hb_hash ((uint32_t) ((const packed_uint32_t *) &this->arrayZ[i])->v);
current = current * 16777619;
}
#endif
for (; i < this->length; i++)
for (auto &v : *this)
{
current = current ^ hb_hash (this->arrayZ[i]);
current = current ^ v;
current = current * 16777619;
}
return current;

Loading…
Cancel
Save