[Python-3000] Set literals (original) (raw)
Georg Brandl g.brandl at gmx.net
Mon Aug 28 22:42:33 CEST 2006
- Previous message: [Python-3000] Set literals
- Next message: [Python-3000] Set literals
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Raymond Hettinger wrote:
Georg Brandl wrote:
In the meantime, I played around with the peepholer and tried to copy the "for x in tupleorlist" optimization for sets. Results are in SF patch #1548082. Did you mean "if x in tupleorlist"? 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 LISTAPPEND opcode. If there isn't going to be a special-cased SETADD, 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 LISTAPPEND 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 LISTAPPEND 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
- Previous message: [Python-3000] Set literals
- Next message: [Python-3000] Set literals
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]