diff --git a/src/egl/main/egldispatchstubs.c b/src/egl/main/egldispatchstubs.c index e02abd7a9e0..bfc3195c779 100644 --- a/src/egl/main/egldispatchstubs.c +++ b/src/egl/main/egldispatchstubs.c @@ -2,6 +2,7 @@ #include "g_egldispatchstubs.h" #include +#include #include "eglcurrent.h" @@ -10,26 +11,21 @@ static const __EGLapiExports *exports; const int __EGL_DISPATCH_FUNC_COUNT = __EGL_DISPATCH_COUNT; int __EGL_DISPATCH_FUNC_INDICES[__EGL_DISPATCH_COUNT + 1]; +static int Compare(const void *l, const void *r) +{ + const char *s = *(const char **)r; + return strcmp(l, s); +} + static int FindProcIndex(const char *name) { - unsigned first = 0; - unsigned last = __EGL_DISPATCH_COUNT - 1; + const char **match = bsearch(name, __EGL_DISPATCH_FUNC_NAMES, + __EGL_DISPATCH_COUNT, sizeof(const char *), Compare); - while (first <= last) { - unsigned middle = (first + last) / 2; - int comp = strcmp(name, - __EGL_DISPATCH_FUNC_NAMES[middle]); + if (match == NULL) + return __EGL_DISPATCH_COUNT; - if (comp > 0) - first = middle + 1; - else if (comp < 0) - last = middle - 1; - else - return middle; - } - - /* Just point to the dummy entry at the end of the respective table */ - return __EGL_DISPATCH_COUNT; + return match - __EGL_DISPATCH_FUNC_NAMES; } void __eglInitDispatchStubs(const __EGLapiExports *exportsTable)