driconf: drop now unused translation facility
[mesa.git] / src / glx / glxglvnd.c
index b7252a791ad5822ca15c6d3e240628de90eeaa9a..bf5c2a06b0cfd845196de4491987cc464ff2c870 100644 (file)
@@ -1,11 +1,11 @@
 #include <string.h>
+#include <stdlib.h>
 #include <X11/Xlib.h>
 
 #include "glvnd/libglxabi.h"
 
 #include "glxglvnd.h"
 
-
 static Bool __glXGLVNDIsScreenSupported(Display *dpy, int screen)
 {
     /* TODO: Think of a better heuristic... */
@@ -17,39 +17,40 @@ 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)
 {
-    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;
-    }
+    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)
 {
     unsigned internalIndex = FindGLXFunction(procName);
 
-    return __glXDispatchFunctions[internalIndex];
+    return (void*)__glXDispatchFunctions[internalIndex];
 }
 
 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;
 }