[Mesa-dev] [PATCH 37/41] glapi: glX_proto_send.py: simplify XCB string conversion

Dylan Baker baker.dylan.c at gmail.com
Fri Apr 1 00:04:54 UTC 2016


This makes the function a little simpler by using a special case for the
initial "ARB", and just walking the str as a sequence rather than
indexing into it.

It also uses a list to join rather than overwritting a str over and over
again.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 src/mapi/glapi/gen/glX_proto_send.py | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py
index 5388163..800f7a3 100644
--- a/src/mapi/glapi/gen/glX_proto_send.py
+++ b/src/mapi/glapi/gen/glX_proto_send.py
@@ -38,20 +38,25 @@ import glX_proto_common
 import license
 
 
-def convertStringForXCB(string_):
-    tmp = ""
-    special = ["ARB"]
-    i = 0
-    while i < len(string_):
-        if string_[i:i+3] in special:
-            tmp = '%s_%s' % (tmp, string_[i:i+3].lower())
-            i = i + 2
-        elif string_[i].isupper():
-            tmp = '%s_%s' % (tmp, string_[i].lower())
+def convert_string_for_xcb(string_):
+    """Convert an OpenGL name into the form XCB wants.
+
+    This means all lower, with more underscores.
+
+    """
+    new = []
+    slice_ = 0
+
+    if string_.startswith('ARB'):
+        new.append('arb_')
+        slice_ = 4
+
+    for c in string_[slice_:]:
+        if c.isupper():
+            new.extend(['_', c.lower()])
         else:
-            tmp = '%s%s' % (tmp, string_[i])
-        i += 1
-    return tmp
+            new.append(c)
+    return ''.join(new)
 
 
 def hash_pixel_function(func):
@@ -633,7 +638,7 @@ class PrintGlxProtoStubs(glX_proto_common.glx_print_proto):
                 print '        printf("\\tUsing XCB.\\n");'
             print '        xcb_connection_t *c = XGetXCBConnection(dpy);'
             print '        (void) __glXFlushRenderBuffer(gc, gc->pc);'
-            xcb_name = 'xcb_glx%s' % convertStringForXCB(name)
+            xcb_name = 'xcb_glx%s' % convert_string_for_xcb(name)
 
             iparams = []
             extra_iparams = []
-- 
2.8.0



More information about the mesa-dev mailing list