diff options
author | Raymond Hettinger <python@rcn.com> | 2004-08-25 03:18:29 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-08-25 03:18:29 (GMT) |
commit | ef0a82b68290ddde9a2f5f88bbe02caa195158a5 (patch) | |
tree | adf2725e1fe596e0441f598416cf9280cc5502e6 /Python/compile.c | |
parent | 08b07def43e2475657bd66c544becb75cae6b4de (diff) | |
download | cpython-ef0a82b68290ddde9a2f5f88bbe02caa195158a5.zip cpython-ef0a82b68290ddde9a2f5f88bbe02caa195158a5.tar.gz cpython-ef0a82b68290ddde9a2f5f88bbe02caa195158a5.tar.bz2 |
Simplify chains of conditional jumps.
(Suggested by Neal Norwitz.)
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/Python/compile.c b/Python/compile.c index 85182de..fe31e6f 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -550,11 +550,34 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen } break; + /* Simplify conditional jump to conditional jump where the + result of the first test implies the success of a similar + test or the failure of the opposite test. + Arises in code like: + "a and b or c" + "a and b and c" + x:JUMP_IF_FALSE y y:JUMP_IF_FALSE z --> x:JUMP_IF_FALSE z + x:JUMP_IF_FALSE y y:JUMP_IF_FALSE z --> x:JUMP_IF_FALSE y+3 + */ + case JUMP_IF_FALSE: + case JUMP_IF_TRUE: + tgt = GETJUMPTGT(codestr, i); + j = codestr[tgt]; + if (j == JUMP_IF_FALSE || j == JUMP_IF_TRUE) { + if (j == opcode) { + tgttgt = GETJUMPTGT(codestr, tgt) - i - 3; + SETARG(codestr, i, tgttgt); + } else { + tgt -= i; + SETARG(codestr, i, tgt); + } + break; + } + /* Intentional fallthrough */ + /* Replace jumps to unconditional jumps */ case FOR_ITER: case JUMP_FORWARD: - case JUMP_IF_FALSE: - case JUMP_IF_TRUE: case JUMP_ABSOLUTE: case CONTINUE_LOOP: case SETUP_LOOP: |