From 2e935514d9790f6f8a7f6639c9564b3d7237d6d3 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Tue, 30 Nov 2021 16:02:05 -0800 Subject: [PATCH] [iter] fix forward implementation in hb_concat(). Add test coverage for forward. --- src/hb-iter.hh | 6 ++++-- src/test-iter.cc | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/hb-iter.hh b/src/hb-iter.hh index db2a50f26..94fd8a0f9 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -627,10 +627,12 @@ struct hb_concat_iter_t : void __forward__ (unsigned n) { if (n > a.len ()) { - a.__forward__ (a.len ()); n -= a.len (); + a.__forward__ (a.len ()); + b.__forward__ (n); + } else { + a.__forward__ (n); } - b.__forward (n); } hb_concat_iter_t __end__ () const { return hb_concat_iter_t (a.end (), b.end ()); } diff --git a/src/test-iter.cc b/src/test-iter.cc index ccc911891..6182eb1e8 100644 --- a/src/test-iter.cc +++ b/src/test-iter.cc @@ -132,8 +132,11 @@ static void test_concat () hb_vector_t d = {1, 2, 3, 4, 5}; auto it1 = hb_concat (a, b); + assert (it1.len () == 5); auto it2 = hb_concat (c, d); + assert (it2.len () == 5); auto it3 = hb_concat (d, c); + assert (it3.len () == 5); for (int i = 0; i < 5; i++) { assert(it1[i] == i + 1); assert(it2[i] == i + 1); @@ -143,6 +146,25 @@ static void test_concat () check_sequential (it1); check_sequential (it2); check_sequential (it3); + + auto it4 = +it1; + it4 += 2; + assert (*it4 == 3); + assert (it4); + assert (it4.len () == 3); + + it4 += 2; + assert (*it4 == 5); + assert (it4); + assert (it4.len () == 1); + + it4++; + assert (!it4); + assert (it4.len () == 0); + + auto it5 = +it1; + it5 += 3; + assert (*it5 == 4); } int