diff options
author | Emil Velikov <[email protected]> | 2016-05-11 14:01:54 -0400 |
---|---|---|
committer | Emil Velikov <[email protected]> | 2016-05-30 17:53:44 +0100 |
commit | eab7e54981017d7b87242505a215a370dfcd5024 (patch) | |
tree | a7275e7f7563589bbc3d6f9a5bf84143b5e9006b /src | |
parent | f9a35bf0125516d9cc660818e7ae2e9dc204b9c5 (diff) |
glx/glvnd: Use strcmp() based binary search in FindGLXFunction()
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 <[email protected]> (v1)
Signed-off-by: Emil Velikov <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/glx/glxglvnd.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/glx/glxglvnd.c b/src/glx/glxglvnd.c index c7c35ca3a14..96cd1fd7e95 100644 --- a/src/glx/glxglvnd.c +++ b/src/glx/glxglvnd.c @@ -19,11 +19,20 @@ static void *__glXGLVNDGetProcAddress(const GLubyte *procName) 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; } |