summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Jackson <[email protected]>2016-09-14 14:02:56 -0400
committerAdam Jackson <[email protected]>2016-11-02 14:52:43 -0400
commitafaaf623d4d95b3ac736e72c744f683a2b804e1d (patch)
tree7f3de5a9b805150eb6de4d369de606bcb8323502
parent8bca8d89ef3babbecc4f3160cbbcb93d33b7a6ee (diff)
glx/glvnd: Use bsearch() in FindGLXFunction instead of open-coding it
Reviewed-by: Eric Engestrom <[email protected]> Signed-off-by: Adam Jackson <[email protected]>
-rw-r--r--src/glx/glxglvnd.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/glx/glxglvnd.c b/src/glx/glxglvnd.c
index 2fc9b0080f8..b6b415114c9 100644
--- a/src/glx/glxglvnd.c
+++ b/src/glx/glxglvnd.c
@@ -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,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);
+
+ if (match == NULL)
+ return DI_FUNCTION_COUNT;
- /* Just point to the dummy entry at the end of the respective table */
- return DI_FUNCTION_COUNT;
+ return match - __glXDispatchTableStrings;
}
static void *__glXGLVNDGetDispatchAddress(const GLubyte *procName)