From: Raymond Hettinger Date: Sat, 30 Oct 2004 08:55:08 +0000 (+0000) Subject: Adopt some peepholer suggestions from Armin Rigo: X-Git-Tag: v2.4b2~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=effb3931ead28d47d240a113c85e8e494273ebfc;p=python Adopt some peepholer suggestions from Armin Rigo: * Use simpler, faster two pass algorithm for markblocks(). * Free the blocks variable if not NULL and exiting without change. * Verify that the rest of the compiler has not set an exception. * Make the test for tuple of constants less restrictive. * Embellish the comment for chained conditional jumps. --- diff --git a/Python/compile.c b/Python/compile.c index 37793caaac..137b46d274 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -406,14 +406,10 @@ tuple_of_constants(unsigned char *codestr, int n, PyObject *consts) /* Pre-conditions */ assert(PyList_CheckExact(consts)); - assert(codestr[0] == LOAD_CONST); assert(codestr[n*3] == BUILD_TUPLE); assert(GETARG(codestr, (n*3)) == n); - - /* Verify chain of n load_constants */ for (i=0 ; i= 0 && - j == lastlc && + j <= lastlc && codestr[h] == LOAD_CONST && ISBASICBLOCK(blocks, h, 3*(j+1)) && tuple_of_constants(&codestr[h], j, consts)) { @@ -647,6 +648,8 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen result of the first test implies the success of a similar test or the failure of the opposite test. Arises in code like: + "if a and b:" + "if a or b:" "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 @@ -755,6 +758,8 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen return code; exitUnchanged: + if (blocks != NULL) + PyMem_Free(blocks); if (addrmap != NULL) PyMem_Free(addrmap); if (codestr != NULL)