From ebf47a95f29dd959319feb7f8728f7c0162a181e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 15 May 2019 15:14:26 -0700 Subject: [PATCH] [iter] Simplify operator!= of iterator filters Both to save ops, and also because lambdas don't implement operator!=, so this was failing in range-based for loop if a lambda was passed to hb_map() or hb_filter(). Just check end-condition assuming that we are comparing to .end() or iterators that are otherwise derived from current iterator. Ie. don't compare things that are expected to be in common. --- src/hb-iter.hh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hb-iter.hh b/src/hb-iter.hh index 140e55365..5df433375 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -378,7 +378,7 @@ struct hb_map_iter_t : void __rewind__ (unsigned n) { it -= n; } hb_map_iter_t __end__ () const { return hb_map_iter_t (it.end (), f); } bool operator != (const hb_map_iter_t& o) const - { return it != o.it || f != o.f; } + { return it != o.it; } private: Iter it; @@ -441,7 +441,7 @@ struct hb_filter_iter_t : void __prev__ () { do --it; while (it && !hb_has (p.get (), hb_get (f.get (), *it))); } hb_filter_iter_t __end__ () const { return hb_filter_iter_t (it.end (), p, f); } bool operator != (const hb_filter_iter_t& o) const - { return it != o.it || p != o.p || f != o.f; } + { return it != o.it; } private: Iter it; @@ -553,6 +553,8 @@ struct hb_zip_iter_t : void __prev__ () { --a; --b; } void __rewind__ (unsigned n) { a -= n; b -= n; } hb_zip_iter_t __end__ () const { return hb_zip_iter_t (a.end (), b.end ()); } + /* Note, we should stop if ANY of the iters reaches end. As such two compare + * unequal if both items are unequal, NOT if either is unequal. */ bool operator != (const hb_zip_iter_t& o) const { return a != o.a && b != o.b; } @@ -621,7 +623,7 @@ struct hb_counter_iter_t : void __rewind__ (unsigned n) { v -= n * step; } hb_counter_iter_t __end__ () const { return hb_counter_iter_t (end_, end_, step); } bool operator != (const hb_counter_iter_t& o) const - { return v != o.v || end_ != o.end_ || step != o.step; } + { return v != o.v; } private: static inline T end_for (T start, T end_, S step)