mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
Simplify chains of conditional jumps.
(Suggested by Neal Norwitz.)
This commit is contained in:
parent
08b07def43
commit
ef0a82b682
1 changed files with 25 additions and 2 deletions
|
@ -550,11 +550,34 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen
|
||||||
}
|
}
|
||||||
break;
|
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 */
|
/* Replace jumps to unconditional jumps */
|
||||||
case FOR_ITER:
|
case FOR_ITER:
|
||||||
case JUMP_FORWARD:
|
case JUMP_FORWARD:
|
||||||
case JUMP_IF_FALSE:
|
|
||||||
case JUMP_IF_TRUE:
|
|
||||||
case JUMP_ABSOLUTE:
|
case JUMP_ABSOLUTE:
|
||||||
case CONTINUE_LOOP:
|
case CONTINUE_LOOP:
|
||||||
case SETUP_LOOP:
|
case SETUP_LOOP:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue