From f88fed5cd8787e3deeec05dac4353337dc02abdd Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Dec 2018 11:11:10 -0500 Subject: [PATCH] [set] Cache length in iterator --- src/hb-set.hh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hb-set.hh b/src/hb-set.hh index 5047e2e6b..bf59c7ae1 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -673,17 +673,20 @@ struct hb_set_t */ struct iter_t : hb_sorted_iter_t { - iter_t (const hb_set_t &s_) : s (s_), v (INVALID) { __next__ (); } + iter_t (const hb_set_t &s_) : + s (s_), v (INVALID), l (s.get_population () + 1) { __next__ (); } typedef hb_codepoint_t __item_type__; hb_codepoint_t __item__ () const { return v; } bool __more__ () const { return v != INVALID; } - void __next__ () { s.next (&v); } + void __next__ () { s.next (&v); if (l) l--; } void __prev__ () { s.previous (&v); } + unsigned __len__ () { return l; } protected: const hb_set_t &s; hb_codepoint_t v; + unsigned l; }; iter_t iter () { return iter_t (*this); } operator iter_t () { return iter (); }