X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=blobdiff_plain;f=src%2Fglx%2Fglxglvnd.c;h=bf5c2a06b0cfd845196de4491987cc464ff2c870;hp=96cd1fd7e95102a81090ae21b70a42a915d32414;hb=HEAD;hpb=eab7e54981017d7b87242505a215a370dfcd5024 diff --git a/src/glx/glxglvnd.c b/src/glx/glxglvnd.c index 96cd1fd7e95..bf5c2a06b0c 100644 --- a/src/glx/glxglvnd.c +++ b/src/glx/glxglvnd.c @@ -1,11 +1,11 @@ #include +#include #include #include "glvnd/libglxabi.h" #include "glxglvnd.h" - static Bool __glXGLVNDIsScreenSupported(Display *dpy, int screen) { /* TODO: Think of a better heuristic... */ @@ -17,43 +17,41 @@ static void *__glXGLVNDGetProcAddress(const GLubyte *procName) return glXGetProcAddressARB(procName); } -static int FindGLXFunction(const GLubyte *name) +static int +compare(const void *l, const void *r) { - 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; + const char *s = *(const char **)r; + return strcmp(l, s); } -static void *__glXGLVNDGetDispatchAddress(const GLubyte *procName) +static unsigned FindGLXFunction(const GLubyte *name) { - int internalIndex = FindGLXFunction(procName); + const char **match; - if (internalIndex >= 0) { - return __glXDispatchFunctions[internalIndex]; - } + match = bsearch(name, __glXDispatchTableStrings, DI_FUNCTION_COUNT, + sizeof(const char *), compare); + + if (match == NULL) + return DI_FUNCTION_COUNT; - return NULL; + return match - __glXDispatchTableStrings; +} + +static void *__glXGLVNDGetDispatchAddress(const GLubyte *procName) +{ + unsigned internalIndex = FindGLXFunction(procName); + + return (void*)__glXDispatchFunctions[internalIndex]; } static void __glXGLVNDSetDispatchIndex(const GLubyte *procName, int index) { - int internalIndex = FindGLXFunction(procName); + unsigned internalIndex = FindGLXFunction(procName); + + if (internalIndex == DI_FUNCTION_COUNT) + return; /* unknown or static dispatch */ - if (internalIndex >= 0) - __glXDispatchTableIndices[internalIndex] = index; + __glXDispatchTableIndices[internalIndex] = index; } _X_EXPORT Bool __glx_Main(uint32_t version, const __GLXapiExports *exports,