From 6a17622a75cf8dea9f1cf5f7b1e4d9be9145ac49 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 22 Jun 2023 18:35:10 -0600 Subject: [PATCH] [array] Speed up iteration These are faster than relying on the random-access methods (forward, rewind, item_it). --- src/hb-array.hh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/hb-array.hh b/src/hb-array.hh index 75805805b..760f90259 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -76,11 +76,24 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> typedef Type& __item_t__; static constexpr bool is_random_access_iterator = true; static constexpr bool has_fast_len = true; + Type& __item__ () const + { + if (unlikely (!length)) return CrapOrNull (Type); + return *arrayZ; + } Type& __item_at__ (unsigned i) const { if (unlikely (i >= length)) return CrapOrNull (Type); return arrayZ[i]; } + void __next__ () + { + if (unlikely (!length)) + return; + length--; + backwards_length++; + arrayZ++; + } void __forward__ (unsigned n) { if (unlikely (n > length)) @@ -89,6 +102,14 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> backwards_length += n; arrayZ += n; } + void __prev__ () + { + if (unlikely (!backwards_length)) + return; + length++; + backwards_length--; + arrayZ--; + } void __rewind__ (unsigned n) { if (unlikely (n > backwards_length))