[Mesa-dev] [PATCH 2/3] glx/glvnd: Use strcmp() based binary search in FindGLXFunction()
Adam Jackson
ajax at redhat.com
Wed May 11 18:01:54 UTC 2016
From: Emil Velikov <emil.velikov at collabora.com>
It will allows us to find the function within 6 attempts, out of the ~80
entry long table.
Reviewed-by: Adam Jackson <ajax at redhat.com>
Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
src/glx/glxglvnd.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/glx/glxglvnd.c b/src/glx/glxglvnd.c
index c7c35ca..9475023 100644
--- a/src/glx/glxglvnd.c
+++ b/src/glx/glxglvnd.c
@@ -19,11 +19,20 @@ static void *__glXGLVNDGetProcAddress(const GLubyte *procName)
static int FindGLXFunction(const GLubyte *name)
{
- int i;
+ unsigned first = 0;
+ unsigned last = DI_FUNCTION_COUNT - 1;
+ unsigned middle = (first + last) / 2;
- for (i = 0; i < DI_FUNCTION_COUNT; i++) {
- if (strcmp((const char *) name, __glXDispatchTableStrings[i]) == 0)
- return i;
+ while (first <= last) {
+ int comp = strcmp((const char *) name,
+ __glXDispatchTableStrings[middle]);
+
+ if (comp < 0)
+ first = middle + 1;
+ else if (comp > 0)
+ last = middle;
+ else
+ return middle;
}
return -1;
}
--
2.7.4
More information about the mesa-dev
mailing list