[bsearch] Micro-optimization

This commit is contained in:
Behdad Esfahbod 2017-10-17 16:32:12 -07:00
parent 41b1984be9
commit d6f612fac8
1 changed files with 2 additions and 1 deletions

View File

@ -1047,11 +1047,12 @@ struct SortedArrayOf : ArrayOf<Type, LenType>
inline int bsearch (const SearchType &x) const
{
/* Hand-coded bsearch here since this is in the hot inner loop. */
const Type *array = this->array;
int min = 0, max = (int) this->len - 1;
while (min <= max)
{
int mid = (min + max) / 2;
int c = this->array[mid].cmp (x);
int c = array[mid].cmp (x);
if (c < 0)
max = mid - 1;
else if (c > 0)