[Mesa-dev] [PATCH 23/41] glapi: gl_XML.py: use collections to simplify functionsIterateByCategory

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


This uses the collections.defaultdict to remove the need to check and
add an empty dict, since defaultdict will call the default factory for
us whenever a KeyError would be raised (by a missing key value).

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

diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py
index 221bd18..91f1091 100644
--- a/src/mapi/glapi/gen/gl_XML.py
+++ b/src/mapi/glapi/gen/gl_XML.py
@@ -29,6 +29,7 @@
 #    Ian Romanick <idr at us.ibm.com>
 
 from decimal import Decimal
+import collections
 import os.path
 import re
 import textwrap
@@ -909,17 +910,13 @@ class gl_api(object):
         Within a category, functions are sorted by name.  If cat is
         not None, then only functions in that category are iterated.
         """
-        lists = [{}, {}, {}, {}]
+        lists = [collections.defaultdict(lambda: {}) for _ in range(4)]
 
         for func in self.functionIterateAll():
-            [cat_name, cat_number] = self.category_dict[func.name]
+            cat_name, cat_number = self.category_dict[func.name]
 
             if cat is None or cat == cat_name:
-                [func_cat_type, key] = classify_category(cat_name, cat_number)
-
-                if key not in lists[func_cat_type]:
-                    lists[func_cat_type][key] = {}
-
+                func_cat_type, key = classify_category(cat_name, cat_number)
                 lists[func_cat_type][key][func.name] = func
 
 
-- 
2.8.0



More information about the mesa-dev mailing list