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

Ian Romanick idr at freedesktop.org
Tue Apr 19 23:16:58 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 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
>  
>  
> 



More information about the mesa-dev mailing list