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

Ian Romanick idr at freedesktop.org
Tue Apr 19 23:18:24 UTC 2016


This patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

On 03/31/2016 05:04 PM, Dylan Baker wrote:
> 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())
> 



More information about the mesa-dev mailing list