It will allows us to find the function within 6 attempts, out of the ~80
entry long table.
v2: calculate middle on each iteration, correctly set the lower limit.
Reviewed-by: Adam Jackson <ajax@redhat.com> (v1)
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
static int FindGLXFunction(const GLubyte *name)
{
- int i;
-
- for (i = 0; i < DI_FUNCTION_COUNT; i++) {
- if (strcmp((const char *) name, __glXDispatchTableStrings[i]) == 0)
- return i;
+ unsigned first = 0;
+ unsigned last = DI_FUNCTION_COUNT - 1;
+
+ while (first <= last) {
+ unsigned middle = (first + last) / 2;
+ int comp = strcmp((const char *) name,
+ __glXDispatchTableStrings[middle]);
+
+ if (comp < 0)
+ first = middle + 1;
+ else if (comp > 0)
+ last = middle - 1;
+ else
+ return middle;
}
return -1;
}