[Piglit] [PATCH v2 1/3] piglit-util-gl: Add piglit_get_gl_enum_from_name

Ilia Mirkin imirkin at alum.mit.edu
Mon Feb 23 10:43:45 PST 2015


On Mon, Feb 23, 2015 at 1:23 PM, Jordan Justen
<jordan.l.justen at intel.com> wrote:
> +    @classmethod
> +    def get_enums_by_name_in_default_namespace(cls, gl_registry):
> +        def append_enum_if_new_value(enum_list, enum):
> +            if enum_list[-1].name != enum.name:
> +                enum_list.append(enum)
> +            return enum_list
> +
> +        enums = (
> +            enum
> +            for enum_group in gl_registry.enum_groups
> +            if enum_group.type == 'default_namespace'
> +            for enum in enum_group.enums
> +        )
> +        enums = sorted(enums, key=lambda enum: enum.name)
> +        enums = reduce(append_enum_if_new_value, enums[1:], [enums[0]])
> +        return enums

I know you're just copying the other function... what you really want
though is a map from enum name to the enum id. Why not just generate
that and avoid the complication?

def foo():
  return dict((enum.name, enum.c_num_literal) for enum_group in ... )

And then when iterating to print them out, you can just iterate over
sorted(enums). IMHO this seems more readable, but your current code is
also correct, so just proposing an alternative. If you change this,
I'd recommend also changing the other function to be similarly less
confusing (with the appropriate change in template).

Cheers,

  -ilia


More information about the Piglit mailing list