[Python-Dev] New opcode to simplifiy/speedup list comprehensions
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 BUILD_LIST 0
> 3 DUP_TOP
> 4 LOAD_ATTR 0 (append) <-- delete this
> line
> 7 STORE_FAST 3 (_[1])
> 10 LOAD_FAST 0 (x)
> 13 GET_ITER
> >> 14 FOR_ITER 20 (to 37)
> 17 STORE_FAST 2 (i)
> 20 LOAD_FAST 3 (_[1])
> 23 LOAD_FAST 2 (i)
> 26 LOAD_FAST 2 (i)
> 29 BINARY_ADD
> 30 CALL_FUNCTION 1 --> replace
with
> LIST_APPEND
> 33 POP_TOP <-- delete
this
> line
> 34 JUMP_ABSOLUTE 14
> >> 37 DELETE_FAST 3 (_[1])
P.S. The patch also removes the DELETE_FAST at position 37
> 40 STORE_FAST 1 (y)
> 43 LOAD_CONST 0 (None)
> 46 RETURN_VALUE
Raymond Hettinger
More information about the Python-Dev
mailing list