X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fglx%2Fglxglvnd.c;h=b6b415114c9fd29afaac83fc6b9841bd21765562;hb=d3540b405b975450b9c2f9d8eb273be062cbf73a;hp=098304d5574909746af915e6edde4b01e7fdc8b5;hpb=62b224d428e04760dc96afb93873d67683337f88;p=mesa.git diff --git a/src/glx/glxglvnd.c b/src/glx/glxglvnd.c index 098304d5574..b6b415114c9 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,26 +17,24 @@ static void *__glXGLVNDGetProcAddress(const GLubyte *procName) return glXGetProcAddressARB(procName); } +static int +compare(const void *l, const void *r) +{ + const char *s = *(const char **)r; + return strcmp(l, s); +} + static unsigned FindGLXFunction(const GLubyte *name) { - int first = 0; - int last = DI_FUNCTION_COUNT - 1; - - while (first <= last) { - int middle = (first + last) / 2; - int comp = strcmp(__glXDispatchTableStrings[middle], - (const char *) name); - - if (comp < 0) - first = middle + 1; - else if (comp > 0) - last = middle - 1; - else - return middle; - } + const char **match; + + match = bsearch(name, __glXDispatchTableStrings, DI_FUNCTION_COUNT, + sizeof(const char *), compare); - /* Just point to the dummy entry at the end of the respective table */ - return DI_FUNCTION_COUNT; + if (match == NULL) + return DI_FUNCTION_COUNT; + + return match - __glXDispatchTableStrings; } static void *__glXGLVNDGetDispatchAddress(const GLubyte *procName) @@ -50,6 +48,9 @@ static void __glXGLVNDSetDispatchIndex(const GLubyte *procName, int index) { unsigned internalIndex = FindGLXFunction(procName); + if (internalIndex == DI_FUNCTION_COUNT) + return; /* unknown or static dispatch */ + __glXDispatchTableIndices[internalIndex] = index; }