[Mesa-dev] [PATCH 24/41] glapi: gl_XML.py: rework gl_api.functionIterateByOffset

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


This reworks this method to use the sorted() built-in rather than taking
the dictionary keys (which involves creating a brand new copy of the
list in memory), sorting it, then iterating the new sorted list and
doing a lookup into the dictionary. Then it does away with building a
list and returning an iterator over that list, instead using an
efficient generator to yield each item one at a time.

The resulting function is less code, commented, and should be a little
more efficient.

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

diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py
index 91f1091..334fd6e 100644
--- a/src/mapi/glapi/gen/gl_XML.py
+++ b/src/mapi/glapi/gen/gl_XML.py
@@ -919,20 +919,12 @@ class gl_api(object):
                 func_cat_type, key = classify_category(cat_name, cat_number)
                 lists[func_cat_type][key][func.name] = func
 
-
-        functions = []
-        for func_cat_type in range(4):
-            keys = lists[func_cat_type].keys()
-            keys.sort()
-
-            for key in keys:
-                names = lists[func_cat_type][key].keys()
-                names.sort()
-
-                for name in names:
-                    functions.append(lists[func_cat_type][key][name])
-
-        return iter(functions)
+        # This needs to be use {iter}items(), (and thus the _) to be able to
+        # sort correctly.
+        for dict_ in lists:
+            for _, items in sorted(dict_.iteritems()):
+                for _, function in sorted(items.iteritems()):
+                    yield function
 
     def functionIterateByOffset(self):
         max_offset = max(f.offset for f in self.functions_by_name.itervalues())
-- 
2.8.0



More information about the mesa-dev mailing list