summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2016-03-29 13:57:35 -0700
committerDylan Baker <baker.dylan.c@gmail.com>2016-03-31 16:03:58 -0700
commitff24610843dea9a5e98b86ed6be16cda73b07181 (patch)
tree0844abe7f150dfd25403654a41ad2451c825f5dd
parent27ab1f4172f54bff477d13cbdb13ee783737cbe7 (diff)
glapi: gl_XML.py: convert gl_api.functionIterateByOffset to a generator
This implementation is somewhat more efficient than the previous, and is less code. It works by replacing one of the list building functions with a generator, so that the last list can be avoided. It also decreases the size of the list that remains by using sorting instead of a sparse list. Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
-rw-r--r--src/mapi/glapi/gen/gl_XML.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py
index f96e44a5a2..221bd18a6d 100644
--- a/src/mapi/glapi/gen/gl_XML.py
+++ b/src/mapi/glapi/gen/gl_XML.py
@@ -940,17 +940,15 @@ class gl_api(object):
def functionIterateByOffset(self):
max_offset = max(f.offset for f in self.functions_by_name.itervalues())
- temp = [None for i in range(max_offset + 1)]
+ temp = []
for func in self.functions_by_name.itervalues():
if func.offset != -1:
- temp[func.offset] = func
+ temp.append((func.offset, func))
- list = []
- for i in range(max_offset + 1):
- if temp[i]:
- list.append(temp[i])
-
- return iter(list)
+ for i, (_, func) in enumerate(sorted(temp, key=lambda i: i[0])):
+ yield func
+ if i > max_offset:
+ break
def functionIterateAll(self):
return self.functions_by_name.itervalues()