[Python-3000] Set literals
Georg Brandl
g.brandl at gmx.net
Mon Aug 28 22:42:33 CEST 2006
Raymond Hettinger wrote:
> Georg Brandl wrote:
>
>>In the meantime, I played around with the peepholer and tried to copy
>>the "for x in tuple_or_list" optimization for sets. Results are in SF
>>patch #1548082.
>>
> Did you mean "if x in tuple_or_list"? IIRC, there was some reason that
> mutable lists were not supposed to be made into constants in for-loops.
Yep, I meant the "if" case.
>>* list comprehensions are special-cased because of the LIST_APPEND opcode.
>> If there isn't going to be a special-cased SET_ADD, it's probably the
>> easiest thing to transform {x for x in a} into set(x for x in a) in the
>> AST step, with "set" of course always being the builtin set.
>
> Set comprehensions and list comprehensions are fundamentally the same
> and therefore should have identical implementations.
>
> While transformation to a generator expression may seem like a good idea
> now, I expect that you'll observe a two-fold performance hit and end-up
> abandoning that approach in favor of the current LIST_APPEND approach.
Of course, the LIST_APPEND approach mustn't be thrown out.
> So it would probably be best to start by teaching the compiler to hide
> the loop variable in a LIST_APPEND approach to list comprehensions and
> then duplicate that approach for set comprehensions.
Okay, I'll look into that direction. But first I'll try to remove duplication
in ast.c, which should be possible since the syntax of listcomps, genexps
and setcomps will be the same in Py3k.
Georg
More information about the Python-3000
mailing list