From b1dc676eaa606660584f3c67f0570457e9f09dd3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 Dec 2019 11:41:24 -0600 Subject: [PATCH] [algs] Reduce one more bsearch() impl Ouch, there were three more left. Down one. Two to go. --- src/hb-open-type.hh | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index af242ece1..725f294b7 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -1026,18 +1026,15 @@ struct VarSizedBinSearchArrayOf template const Type *bsearch (const T &key) const { - unsigned int size = header.unitSize; - int min = 0, max = (int) get_length () - 1; - while (min <= max) - { - int mid = ((unsigned int) min + (unsigned int) max) / 2; - const Type *p = (const Type *) (((const char *) &bytesZ) + (mid * size)); - int c = p->cmp (key); - if (c < 0) max = mid - 1; - else if (c > 0) min = mid + 1; - else return p; - } - return nullptr; + unsigned pos; + return hb_bsearch_impl (&pos, + key, + (const void *) bytesZ, + get_length (), + header.unitSize, + _hb_cmp_method) + ? (const Type *) (((const char *) &bytesZ) + (pos * header.unitSize)) + : nullptr; } private: