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

Jordan Justen jordan.l.justen at intel.com
Mon Feb 23 13:15:15 PST 2015


On 2015-02-23 10:43:45, Ilia Mirkin wrote:
> 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...

Yes, I was trying to be lazy. :) Apparently this code is a little more
complex than in needs to be, so I'll try a v3.

> what you really want
> though is a map from enum name to the enum id. Why not just generate
> that and avoid the complication?

I don't think a dict is too helpful, since it needs to be sorted and
mapped two different ways, and the mapping is not 1:1.

-Jordan

> 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