Add a specialization of array_t:hash for hb_bytes_t and hb_ubytes_t.
This commit is contained in:
parent
95ab110cd9
commit
05bcdb39d8
|
@ -99,7 +99,14 @@ struct hb_array_t : hb_iter_with_fallback_t<hb_array_t<Type>, Type&>
|
||||||
template <typename T> operator T * () const { return arrayZ; }
|
template <typename T> operator T * () const { return arrayZ; }
|
||||||
|
|
||||||
HB_INTERNAL bool operator == (const hb_array_t &o) const;
|
HB_INTERNAL bool operator == (const hb_array_t &o) const;
|
||||||
HB_INTERNAL uint32_t hash () const;
|
|
||||||
|
uint32_t hash () const {
|
||||||
|
uint32_t current = 0;
|
||||||
|
for (unsigned int i = 0; i < this->length; i++) {
|
||||||
|
current = current * 31 + hb_hash (this->arrayZ[i]);
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compare, Sort, and Search.
|
* Compare, Sort, and Search.
|
||||||
|
@ -339,21 +346,28 @@ bool hb_array_t<T>::operator == (const hb_array_t<T> &o) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
/* TODO Specialize opeator== for hb_bytes_t and hb_ubytes_t. */
|
||||||
uint32_t hb_array_t<T>::hash () const
|
|
||||||
{
|
template <>
|
||||||
|
inline uint32_t hb_array_t<const char>::hash () const {
|
||||||
uint32_t current = 0;
|
uint32_t current = 0;
|
||||||
for (unsigned int i = 0; i < this->length; i++) {
|
for (unsigned int i = 0; i < this->length; i++)
|
||||||
current = current * 31 + hb_hash (this->arrayZ[i]);
|
current = current * 31 + (uint32_t) (this->arrayZ[i] * 2654435761u);
|
||||||
}
|
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline uint32_t hb_array_t<const unsigned char>::hash () const {
|
||||||
|
uint32_t current = 0;
|
||||||
|
for (unsigned int i = 0; i < this->length; i++)
|
||||||
|
current = current * 31 + (uint32_t) (this->arrayZ[i] * 2654435761u);
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef hb_array_t<const char> hb_bytes_t;
|
typedef hb_array_t<const char> hb_bytes_t;
|
||||||
typedef hb_array_t<const unsigned char> hb_ubytes_t;
|
typedef hb_array_t<const unsigned char> hb_ubytes_t;
|
||||||
|
|
||||||
/* TODO Specialize opeator==/hash() for hb_bytes_t and hb_ubytes_t. */
|
|
||||||
//template <>
|
|
||||||
//uint32_t hb_array_t<const char>::hash () const { return 0; }
|
|
||||||
|
|
||||||
#endif /* HB_ARRAY_HH */
|
#endif /* HB_ARRAY_HH */
|
||||||
|
|
|
@ -713,9 +713,7 @@ static inline bool intersects_array (const hb_set_t *glyphs,
|
||||||
const void *intersects_data)
|
const void *intersects_data)
|
||||||
{
|
{
|
||||||
for (const HBUINT16 &_ : + hb_iter (values, count))
|
for (const HBUINT16 &_ : + hb_iter (values, count))
|
||||||
{
|
|
||||||
if (intersects_func (glyphs, _, intersects_data)) return true;
|
if (intersects_func (glyphs, _, intersects_data)) return true;
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue