diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index a7592828a..e66f2b4ca 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -635,22 +635,19 @@ struct hb_sorted_array_t : hb_array_t inline hb_sorted_array_t (Type *array_, unsigned int len_) : hb_array_t (array_, len_) {} template - inline Type *bsearch (const T &x, - Type *not_found = nullptr) + inline Type *bsearch (const T &x, Type *not_found = nullptr) { unsigned int i; return bfind (x, &i) ? &this->arrayZ[i] : not_found; } template - inline const Type *bsearch (const T &x, - const Type *not_found = nullptr) const + inline const Type *bsearch (const T &x, const Type *not_found = nullptr) const { unsigned int i; return bfind (x, &i) ? &this->arrayZ[i] : not_found; } template - inline bool bfind (const T &x, - unsigned int *i = nullptr) const + inline bool bfind (const T &x, unsigned int *i = nullptr) const { int min = 0, max = (int) this->len - 1; const Type *array = this->arrayZ; diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index e384a7ad5..0ea884314 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -551,14 +551,10 @@ struct ArrayOf template inline Type &lsearch (const T &x) - { - return *as_array ().lsearch (x, &Crap (T)); - } + { return *as_array ().lsearch (x, &Crap (T)); } template inline const Type &lsearch (const T &x) const - { - return *as_array ().lsearch (x, &Null (T)); - } + { return *as_array ().lsearch (x, &Null (T)); } inline void qsort (void) { @@ -745,46 +741,20 @@ struct ArrayOfM1 template struct SortedArrayOf : ArrayOf { + inline hb_sorted_array_t as_array (void) + { return hb_sorted_array (this->arrayZ, this->len); } + inline hb_sorted_array_t as_array (void) const + { return hb_sorted_array (this->arrayZ, this->len); } + template inline Type &bsearch (const T &x) - { - unsigned int i; - return bfind (x, &i) ? this->arrayZ[i] : Crap(Type); - } + { return *as_array ().bsearch (x, &Crap (Type)); } template inline const Type &bsearch (const T &x) const - { - unsigned int i; - return bfind (x, &i) ? this->arrayZ[i] : Null(Type); - } + { return *as_array ().bsearch (x, &Null (Type)); } template inline bool bfind (const T &x, unsigned int *i = nullptr) const - { - int min = 0, max = (int) this->len - 1; - const Type *array = this->arrayZ; - while (min <= max) - { - int mid = ((unsigned int) min + (unsigned int) max) / 2; - int c = array[mid].cmp (x); - if (c < 0) - max = mid - 1; - else if (c > 0) - min = mid + 1; - else - { - if (i) - *i = mid; - return true; - } - } - if (i) - { - if (max < 0 || (max < (int) this->len && array[max].cmp (x) > 0)) - max++; - *i = max; - } - return false; - } + { return as_array ().bfind (x, i); } }; /* diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 14967a410..085523f84 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -236,36 +236,21 @@ struct hb_vector_t } template - inline Type *lsearch (const T &x, - Type *not_found = nullptr) - { - return as_array ().lsearch (x, not_found); - } + inline Type *lsearch (const T &x, Type *not_found = nullptr) + { return as_array ().lsearch (x, not_found); } template - inline const Type *lsearch (const T &x, - const Type *not_found = nullptr) const - { - return as_array ().lsearch (x, not_found); - } + inline const Type *lsearch (const T &x, const Type *not_found = nullptr) const + { return as_array ().lsearch (x, not_found); } template - inline Type *bsearch (const T &x, - Type *not_found = nullptr) - { - return as_sorted_array ().bsearch (x, not_found); - } + inline Type *bsearch (const T &x, Type *not_found = nullptr) + { return as_sorted_array ().bsearch (x, not_found); } template - inline const Type *bsearch (const T &x, - const Type *not_found = nullptr) const - { - return as_sorted_array ().bsearch (x, not_found); - } + inline const Type *bsearch (const T &x, const Type *not_found = nullptr) const + { return as_sorted_array ().bsearch (x, not_found); } template - inline bool bfind (const T &x, - unsigned int *i = nullptr) const - { - return as_sorted_array ().bfind (x, i); - } + inline bool bfind (const T &x, unsigned int *i = nullptr) const + { return as_sorted_array ().bfind (x, i); } };