[pypy-commit] pypy default: Optimize the bytecode for the case "if a or b:"
arigo
noreply at buildbot.pypy.org
Fri Dec 26 18:46:32 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r75130:534bd32933a1
Date: 2014-12-26 18:45 +0100
http://bitbucket.org/pypy/pypy/changeset/534bd32933a1/
Log: Optimize the bytecode for the case "if a or b:"
diff --git a/pypy/interpreter/astcompiler/optimize.py b/pypy/interpreter/astcompiler/optimize.py
--- a/pypy/interpreter/astcompiler/optimize.py
+++ b/pypy/interpreter/astcompiler/optimize.py
@@ -83,17 +83,16 @@
class __extend__(ast.BoolOp):
- def _accept_jump_if_any_is(self, gen, condition, target):
- self.values[0].accept_jump_if(gen, condition, target)
- for i in range(1, len(self.values)):
+ def _accept_jump_if_any_is(self, gen, condition, target, skip_last=0):
+ for i in range(len(self.values) - skip_last):
self.values[i].accept_jump_if(gen, condition, target)
def accept_jump_if(self, gen, condition, target):
if condition and self.op == ast.And or \
(not condition and self.op == ast.Or):
end = gen.new_block()
- self._accept_jump_if_any_is(gen, not condition, end)
- gen.emit_jump(ops.JUMP_FORWARD, target)
+ self._accept_jump_if_any_is(gen, not condition, end, skip_last=1)
+ self.values[-1].accept_jump_if(gen, condition, target)
gen.use_next_block(end)
else:
self._accept_jump_if_any_is(gen, condition, target)
More information about the pypy-commit
mailing list