[algs] Reduce one more bsearch() impl

Ouch, there were three more left.  Down one.  Two to go.
This commit is contained in:
Behdad Esfahbod 2019-12-10 11:41:24 -06:00
parent 6f76c325e5
commit b1dc676eaa
1 changed files with 9 additions and 12 deletions

View File

@ -1026,18 +1026,15 @@ struct VarSizedBinSearchArrayOf
template <typename T>
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<T, Type>)
? (const Type *) (((const char *) &bytesZ) + (pos * header.unitSize))
: nullptr;
}
private: