diff --git a/Misc/NEWS b/Misc/NEWS index 9f27fd73651..f543eca3734 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.4 alpha 1? Core and builtins ----------------- +- Optimized the byte coding for multiple assignments like "a,b=b,a" and + "a,b,c=1,2,3". Improves their speed by 25% to 30%. + - Limit the nested depth of a tuple for the second argument to isinstance() and issubclass() to the recursion limit of the interpreter. Fixes bug #858016 . diff --git a/Python/compile.c b/Python/compile.c index f58fb83efce..328c57bb0fd 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -327,6 +327,43 @@ intern_strings(PyObject *tuple) #define ABSOLUTE_JUMP(op) (op==JUMP_ABSOLUTE || op==CONTINUE_LOOP) #define GETJUMPTGT(arr, i) (GETARG(arr,i) + (ABSOLUTE_JUMP(arr[i]) ? 0 : i+3)) #define SETARG(arr, i, val) arr[i+2] = val>>8; arr[i+1] = val & 255 +#define CODESIZE(op) (HAS_ARG(op) ? 3 : 1) +#define ISBASICBLOCK(blocks, start, bytes) (blocks[start]==blocks[start+bytes-1]) + +static unsigned int * +markblocks(unsigned char *code, int len) +{ + unsigned int *blocks = PyMem_Malloc(len*sizeof(int)); + int i,j, opcode, oldblock, newblock, blockcnt = 0; + + if (blocks == NULL) + return NULL; + memset(blocks, 0, len*sizeof(int)); + for (i=0 ; i