Antoine Pitrou <pit...@free.fr> added the comment: Here is an optional patch which provides the two opcodes I was talking about (I've called them POP_OR_JUMP and JUMP_OR_POP). Together with a bit of work on the peepholer they make the bytecode expression of boolean calculations very concise.
A somewhat contrived example: "f = lambda x,y,z,v: (z if x else y) or v" Without the patch: 1 0 LOAD_FAST 0 (x) 3 JUMP_IF_FALSE 7 (to 13) 6 POP_TOP 7 LOAD_FAST 2 (z) 10 JUMP_FORWARD 4 (to 17) >> 13 POP_TOP 14 LOAD_FAST 1 (y) >> 17 JUMP_IF_TRUE 4 (to 24) 20 POP_TOP 21 LOAD_FAST 3 (v) >> 24 RETURN_VALUE With the patch: 1 0 LOAD_FAST 0 (x) 3 POP_JUMP_IF_FALSE 12 6 LOAD_FAST 2 (z) 9 JUMP_FORWARD 3 (to 15) >> 12 LOAD_FAST 1 (y) >> 15 JUMP_OR_POP 21 18 LOAD_FAST 3 (v) >> 21 RETURN_VALUE Added file: http://bugs.python.org/file12421/condbranches-plus.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue4715> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com