From 7129b79406fbbf53e08fa55623b5d8e2fa34e649 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 29 Nov 2022 15:33:07 -0700 Subject: [PATCH] [open-type] Add faster range-based loop to array types --- src/hb-open-type.hh | 12 ++++++++++++ src/hb-vector.hh | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 9180b1300..ccbbec517 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -646,6 +646,10 @@ struct ArrayOf operator iter_t () const { return iter (); } operator writer_t () { return writer (); } + /* Faster range-based for loop. */ + const Type *begin () const { return arrayZ; } + const Type *end () const { return arrayZ + len; } + template Type &lsearch (const T &x, Type ¬_found = Crap (Type)) { return *as_array ().lsearch (x, ¬_found); } @@ -819,6 +823,10 @@ struct HeadlessArrayOf operator iter_t () const { return iter (); } operator writer_t () { return writer (); } + /* Faster range-based for loop. */ + const Type *begin () const { return arrayZ; } + const Type *end () const { return arrayZ + get_length (); } + bool serialize (hb_serialize_context_t *c, unsigned int items_len) { TRACE_SERIALIZE (this); @@ -935,6 +943,10 @@ struct SortedArrayOf : ArrayOf operator iter_t () const { return iter (); } operator writer_t () { return writer (); } + /* Faster range-based for loop. */ + const Type *begin () const { return this->arrayZ; } + const Type *end () const { return this->arrayZ + this->len; } + bool serialize (hb_serialize_context_t *c, unsigned int items_len) { TRACE_SERIALIZE (this); diff --git a/src/hb-vector.hh b/src/hb-vector.hh index e43d4fce3..8b50f7802 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -172,7 +172,7 @@ struct hb_vector_t operator iter_t () const { return iter (); } operator writer_t () { return writer (); } - /* Faster range-based for loop without constructing an hb_array_t. */ + /* Faster range-based for loop. */ Type *begin () const { return arrayZ; } Type *end () const { return arrayZ + length; }