[Mesa-dev] [PATCH 20/41] glapi: gl_XML.py: make gl_api.categoryIterate a generator

Dylan Baker baker.dylan.c at gmail.com
Tue Apr 19 23:26:12 UTC 2016


Quoting Ian Romanick (2016-04-19 15:14:59)
> On 03/31/2016 05:04 PM, Dylan Baker wrote:
> > 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 at intel.com>
> > ---
> >  src/mapi/glapi/gen/gl_XML.py | 13 +++++--------
> >  1 file changed, 5 insertions(+), 8 deletions(-)
> > 
> > diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py
> > index 9298995..b7178d6 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.
> > +
> 
> Spurious blank line?
> 
> With that fixed (or not, if there's a reason for it), this patch is
> 
> Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

It probably doesn't need to be in the patch, and I'll drop that in v2.
Python recommends it because of emacs, but I don't use emacs so I didn't
really understand the reason for it.

> 
> >          """
> > -        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:
> > 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160419/3099468d/attachment.sig>


More information about the mesa-dev mailing list