[Python-Dev] New opcode to simplifiy/speedup list comprehensions (original) (raw)

Raymond Hettinger python at rcn.com
Sat Mar 6 08:53:56 EST 2004


>>> def f(x): y = [i+i for i in x]

>>> dis(f) 2 0 BUILDLIST 0 3 DUPTOP 4 LOADATTR 0 (append) <-- delete this_ _line_ _7 STOREFAST 3 ([1])_ _10 LOADFAST 0 (x)_ _13 GETITER_ _>> 14 FORITER 20 (to 37) 17 STOREFAST 2 (i) 20 LOADFAST 3 ([1]) 23 LOADFAST 2 (i) 26 LOADFAST 2 (i) 29 BINARYADD 30 CALLFUNCTION 1 --> replace with LISTAPPEND 33 POPTOP <-- delete_ this _line_ _34 JUMPABSOLUTE 14_ _>> 37 DELETEFAST 3 ([1])

P.S. The patch also removes the DELETE_FAST at position 37

40 STOREFAST 1 (y) 43 LOADCONST 0 (None) 46 RETURNVALUE

Raymond Hettinger



More information about the Python-Dev mailing list