From 05bcdb39d8648c49f7984c404aee096f2ad1d655 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 21 Oct 2019 16:10:06 -0700 Subject: [PATCH] Add a specialization of array_t:hash for hb_bytes_t and hb_ubytes_t. --- src/hb-array.hh | 34 ++++++++++++++++++++++++---------- src/hb-ot-layout-gsubgpos.hh | 2 -- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/hb-array.hh b/src/hb-array.hh index 470531852..09d10b47c 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -99,7 +99,14 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> template operator T * () const { return arrayZ; } 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. @@ -339,21 +346,28 @@ bool hb_array_t::operator == (const hb_array_t &o) const return true; } -template -uint32_t hb_array_t::hash () const -{ +/* TODO Specialize opeator== for hb_bytes_t and hb_ubytes_t. */ + +template <> +inline uint32_t hb_array_t::hash () const { uint32_t current = 0; - for (unsigned int i = 0; i < this->length; i++) { - current = current * 31 + hb_hash (this->arrayZ[i]); - } + for (unsigned int i = 0; i < this->length; i++) + current = current * 31 + (uint32_t) (this->arrayZ[i] * 2654435761u); return current; } +template <> +inline uint32_t hb_array_t::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 hb_bytes_t; typedef hb_array_t hb_ubytes_t; -/* TODO Specialize opeator==/hash() for hb_bytes_t and hb_ubytes_t. */ -//template <> -//uint32_t hb_array_t::hash () const { return 0; } + #endif /* HB_ARRAY_HH */ diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 4f0e17b0c..11b5b5f5f 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -713,9 +713,7 @@ static inline bool intersects_array (const hb_set_t *glyphs, const void *intersects_data) { for (const HBUINT16 &_ : + hb_iter (values, count)) - { if (intersects_func (glyphs, _, intersects_data)) return true; - } return false; }