From eab191fd9c851cb7881163ddd5e11a2ebc58cef4 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 2 Oct 2019 14:28:53 -0700 Subject: [PATCH] Rewrite hash and == function for hb_array_t as a plain loop. Profling showed that the current implementation were accounting for nearly all processing time in some cases. These implementations look to be about 10x faster. --- src/hb-array.hh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/hb-array.hh b/src/hb-array.hh index 20d3eb701..470531852 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -332,20 +332,21 @@ hb_sorted_array (T (&array_)[length_]) template bool hb_array_t::operator == (const hb_array_t &o) const { - return length == o.length && - + hb_zip (*this, o) - | hb_map ([] (hb_pair_t &&_) { return _.first == _.second; }) - | hb_all - ; + if (o.length != this->length) return false; + for (unsigned int i = 0; i < this->length; i++) { + if (this->arrayZ[i] != o.arrayZ[i]) return false; + } + return true; } + template uint32_t hb_array_t::hash () const { - return - + hb_iter (*this) - | hb_map (hb_hash) - | hb_reduce ([] (uint32_t a, uint32_t b) { return a * 31 + b; }, 0) - ; + uint32_t current = 0; + for (unsigned int i = 0; i < this->length; i++) { + current = current * 31 + hb_hash (this->arrayZ[i]); + } + return current; } typedef hb_array_t hb_bytes_t;