Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e56131b

Browse files
committed
Issue 2260: Small peephole optimization -- eliminate unnecessary POP_TOP /JUMP_FORWARD 1 pairs.
1 parent a2a08fb commit e56131b

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Python/peephole.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,16 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
430430
cumlc = 0;
431431
break;
432432

433+
/* Replace POP_TOP JUMP_FORWARD 1 POP_TOP
434+
with NOP NOP NOP NOP POP_TOP. */
435+
case POP_TOP:
436+
if (UNCONDITIONAL_JUMP(codestr[i+1]) &&
437+
GETJUMPTGT(codestr, i+1) == i+5 &&
438+
codestr[i+4] == POP_TOP &&
439+
ISBASICBLOCK(blocks,i,4))
440+
memset(codestr+i, NOP, 4);
441+
break;
442+
433443
/* Try to fold tuples of constants (includes a case for lists
434444
which are only used for "in" and "not in" tests).
435445
Skip over BUILD_SEQN 1 UNPACK_SEQN 1.

0 commit comments

Comments
 (0)