New submission from Neal Norwitz:
>>> def foo():
... if x:
... yield None
...
>>> dis.dis(foo)
2 0 LOAD_GLOBAL 0 (x)
3 POP_JUMP_IF_FALSE 14
3 6 LOAD_CONST 0 (None)
9 YIELD_VALUE
10 POP_TOP
11 JUMP_FORWARD 0 (to 14)
>> 14 LOAD_CONST 0 (None)
17 RETURN_VALUE
The JUMP_FORWARD at 11 is not necessary and is not in place with a return in
the code:
>>> def foo():
... if x:
... return None
...
>>> dis.dis(foo)
2 0 LOAD_GLOBAL 0 (x)
3 POP_JUMP_IF_FALSE 10
3 6 LOAD_CONST 0 (None)
9 RETURN_VALUE
>> 10 LOAD_CONST 0 (None)
13 RETURN_VALUE
----------
components: Interpreter Core
messages: 185708
nosy: Neal.Norwitz
priority: normal
severity: normal
status: open
title: missed peephole optimization (unnecessary jump at end of function after
yield)
type: performance
versions: Python 2.7
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue17607>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com