[hash] Use fasthash for integer hash

This seems to speed things up surprisingly.
This commit is contained in:
Behdad Esfahbod committed 2023-05-09 12:49:37 -06:00
1 parent a58bbe5408
commit bdaa74d25f
1 file changed
+8 -2
+8 -2
View File
@@ -307,6 +307,12 @@ static inline uint32_t fasthash32(const void *buf, size_t len, uint32_t seed)
return h - (h >> 32);
}
template <typename T> // This line speeds things up. Go figure...
static inline uint32_t _hb_hash32 (uint32_t v)
{
return fasthash32 (&v, sizeof (v), 0);
}
struct
{
private:
@@ -318,11 +324,11 @@ struct
//
template <typename T,
hb_enable_if (std::is_integral<T>::value && sizeof (T) <= sizeof (uint32_t))> constexpr auto
impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, v * 8388607u /* Mersenne prime */)
impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, _hb_hash32 (v))
template <typename T,
hb_enable_if (std::is_integral<T>::value && sizeof (T) > sizeof (uint32_t))> constexpr auto
impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, (v * 8388607u) ^ ((v >> 32) * 8388607u) /* Mersenne prime */)
impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, _hb_hash32 (v) ^ _hb_hash32 (v >> 32))
template <typename T> constexpr auto
impl (const T& v, hb_priority<0>) const HB_RETURN (uint32_t, std::hash<hb_decay<decltype (hb_deref (v))>>{} (hb_deref (v)))