diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index c133a532d..1d5bb3520 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -575,9 +575,24 @@ struct hb_array_t inline unsigned int get_size (void) const { return len * sizeof (Type); } - template - inline bool sanitize (hb_sanitize_context_t *c) const - { return c->check_array (arrayZ, len); } + template + inline Type *lsearch (const T &x, Type *not_found = nullptr) + { + unsigned int count = len; + for (unsigned int i = 0; i < count; i++) + if (!this->arrayZ[i].cmp (x)) + return &this->arrayZ[i]; + return not_found; + } + template + inline const Type *lsearch (const T &x, const Type *not_found = nullptr) const + { + unsigned int count = len; + for (unsigned int i = 0; i < count; i++) + if (!this->arrayZ[i].cmp (x)) + return &this->arrayZ[i]; + return not_found; + } template inline operator T * (void) const { return arrayZ; } @@ -601,6 +616,11 @@ struct hb_array_t inline void free (void) { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; } + template + inline bool sanitize (hb_sanitize_context_t *c) const + { return c->check_array (arrayZ, len); } + + public: Type *arrayZ; unsigned int len; }; diff --git a/src/hb-vector.hh b/src/hb-vector.hh index e17f8897d..d1fb65df8 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -229,22 +229,14 @@ struct hb_vector_t } template - inline Type *lsearch (const T &x) + inline Type *lsearch (const T &x, Type *not_found = nullptr) { - Type *array = arrayZ(); - for (unsigned int i = 0; i < len; i++) - if (0 == array[i].cmp (x)) - return &array[i]; - return nullptr; + return as_array ().lsearch (x, not_found); } template - inline const Type *lsearch (const T &x) const + inline const Type *lsearch (const T &x, const Type *not_found = nullptr) const { - const Type *array = arrayZ(); - for (unsigned int i = 0; i < len; i++) - if (0 == array[i].cmp (x)) - return &array[i]; - return nullptr; + return as_array ().lsearch (x, not_found); } template