#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... */
return glXGetProcAddressARB(procName);
}
-static int FindGLXFunction(const GLubyte *name)
+static int
+compare(const void *l, const void *r)
{
- int i;
+ const char *s = *(const char **)r;
+ return strcmp(l, s);
+}
- for (i = 0; i < DI_FUNCTION_COUNT; i++) {
- if (strcmp((const char *) name, __glXDispatchTableStrings[i]) == 0)
- return i;
- }
- return -1;
+static unsigned FindGLXFunction(const GLubyte *name)
+{
+ const char **match;
+
+ match = bsearch(name, __glXDispatchTableStrings, DI_FUNCTION_COUNT,
+ sizeof(const char *), compare);
+
+ if (match == NULL)
+ return DI_FUNCTION_COUNT;
+
+ return match - __glXDispatchTableStrings;
}
static void *__glXGLVNDGetDispatchAddress(const GLubyte *procName)
{
- int internalIndex = FindGLXFunction(procName);
+ unsigned internalIndex = FindGLXFunction(procName);
- if (internalIndex >= 0) {
- return __glXDispatchFunctions[internalIndex];
- }
-
- return NULL;
+ return __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,