From 099ecfbec9a2a8bdca0ce9afdad4e1158b8e2169 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 1 Nov 2004 15:19:11 +0000 Subject: Simplify and future proof NOP counting in the peepholer. No longer assumes that the input is NOP free. --- Python/compile.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/Python/compile.c b/Python/compile.c index f808307..d47f8d5 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -536,8 +536,7 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen goto exitUnchanged; assert(PyList_Check(consts)); - for (i=0, nops=0 ; i a is not b @@ -575,7 +573,6 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen continue; SETARG(codestr, i, (j^1)); codestr[i+3] = NOP; - nops++; break; /* Replace LOAD_GLOBAL/LOAD_NAME None with LOAD_CONST None */ @@ -604,7 +601,6 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen !PyObject_IsTrue(PyList_GET_ITEM(consts, j))) continue; memset(codestr+i, NOP, 7); - nops += 7; break; /* Try to fold tuples of constants. @@ -619,7 +615,6 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen codestr[h] == LOAD_CONST && ISBASICBLOCK(blocks, h, 3*(j+1)) && tuple_of_constants(&codestr[h], j, consts)) { - nops += 3 * j; break; } /* Intentional fallthrough */ @@ -631,16 +626,13 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen continue; if (j == 1) { memset(codestr+i, NOP, 6); - nops += 6; } else if (j == 2) { codestr[i] = ROT_TWO; memset(codestr+i+1, NOP, 5); - nops += 5; } else if (j == 3) { codestr[i] = ROT_THREE; codestr[i+1] = ROT_TWO; memset(codestr+i+2, NOP, 4); - nops += 4; } break; @@ -704,12 +696,16 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen !ISBASICBLOCK(blocks,i,5)) continue; memset(codestr+i+1, NOP, 4); - nops += 4; break; } } /* Fixup linenotab */ + for (i=0, nops=0 ; i