diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2016-03-29 13:23:44 -0700 |
---|---|---|
committer | Dylan Baker <baker.dylan.c@gmail.com> | 2016-03-31 16:03:58 -0700 |
commit | a29bd0b966210ed5c4b8610e4170a09de7d5e18d (patch) | |
tree | ee31607c6eccfd05f7cab837ef678a4341481773 | |
parent | 0546cc6ad80364d9fa5126d2d528d4ecf27df563 (diff) |
glapi: gl_XML.py: make gl_api.categoryIterate a generator
This does basically the same thing as the previous implementation,
although it uses sorted() to act on the dictionary without first copying
the keys out into a list, and then indexing back into the dict; and uses
yield to make the method a generator, removing the need to make another
list.
Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
-rw-r--r-- | src/mapi/glapi/gen/gl_XML.py | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py index 9298995d07..b7178d6e85 100644 --- a/src/mapi/glapi/gen/gl_XML.py +++ b/src/mapi/glapi/gen/gl_XML.py @@ -964,16 +964,13 @@ class gl_api(object): Iterate over all known categories in the order specified by classify_category. Each iterated value is a tuple of the name and number (which may be None) of the category. + """ - list = [] for cat_type in xrange(4): - keys = self.categories[cat_type].keys() - keys.sort() - - for key in keys: - list.append(self.categories[cat_type][key]) - - return iter(list) + # iteritems and _ are required to make sorted() work, since we want + # to sort by key but return the the value. + for _, v in sorted(self.categories[cat_type].iteritems()): + yield v def get_category_for_name(self, name): if name in self.category_dict: |