summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-11-18 00:07:10 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-11-18 00:07:10 (GMT)
commite56131b60e6c2e63bcb6ecc2a6b7964d74ab847d (patch)
treef4a7a81fd451ece001a74109abe037068c71c85a
parenta2a08fb932793ffca1e42314c924e0590c6a1038 (diff)
downloadcpython-e56131b60e6c2e63bcb6ecc2a6b7964d74ab847d.zip
cpython-e56131b60e6c2e63bcb6ecc2a6b7964d74ab847d.tar.gz
cpython-e56131b60e6c2e63bcb6ecc2a6b7964d74ab847d.tar.bz2
Issue 2260: Small peephole optimization -- eliminate unnecessary POP_TOP /JUMP_FORWARD 1 pairs.
-rw-r--r--Python/peephole.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/Python/peephole.c b/Python/peephole.c
index b9b26fc..d31c89b 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.