From: Raymond Hettinger Date: Tue, 18 Nov 2008 00:07:10 +0000 (+0000) Subject: Issue 2260: Small peephole optimization -- eliminate unnecessary POP_TOP /JUMP_FORWAR... X-Git-Tag: v3.0rc3~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e56131b60e6c2e63bcb6ecc2a6b7964d74ab847d;p=python Issue 2260: Small peephole optimization -- eliminate unnecessary POP_TOP /JUMP_FORWARD 1 pairs. --- diff --git a/Python/peephole.c b/Python/peephole.c index b9b26fc0a7..d31c89b86e 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -430,6 +430,16 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, cumlc = 0; break; + /* Replace POP_TOP JUMP_FORWARD 1 POP_TOP + with NOP NOP NOP NOP POP_TOP. */ + case POP_TOP: + if (UNCONDITIONAL_JUMP(codestr[i+1]) && + GETJUMPTGT(codestr, i+1) == i+5 && + codestr[i+4] == POP_TOP && + ISBASICBLOCK(blocks,i,4)) + memset(codestr+i, NOP, 4); + break; + /* Try to fold tuples of constants (includes a case for lists which are only used for "in" and "not in" tests). Skip over BUILD_SEQN 1 UNPACK_SEQN 1.