mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-14 17:13:40 +00:00
[bytes] Simplify hash function
Part of https://github.com/harfbuzz/harfbuzz/issues/4227
This commit is contained in:
parent
0e02680803
commit
c005e3a2e3
1 changed files with 4 additions and 28 deletions
|
@ -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)
|
||||
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<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)
|
||||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue