[Python-checkins] python/dist/src/Python compile.c,2.306,2.307

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Fri Jul 16 14:13:41 CEST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28894

Modified Files:
	compile.c 
Log Message:
Treat None as a constant.

Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.306
retrieving revision 2.307
diff -C2 -d -r2.306 -r2.307
*** compile.c	8 Jul 2004 01:49:00 -0000	2.306
--- compile.c	16 Jul 2004 12:13:38 -0000	2.307
***************
*** 364,368 ****
  
  static PyObject *
! optimize_code(PyObject *code, PyObject* consts)
  {
  	int i, j, codelen;
--- 364,368 ----
  
  static PyObject *
! optimize_code(PyObject *code, PyObject* consts, PyObject *names)
  {
  	int i, j, codelen;
***************
*** 370,373 ****
--- 370,374 ----
  	unsigned char *codestr;
  	unsigned int *blocks;
+ 	char *name;
  
  	/* Make a modifiable copy of the code string */
***************
*** 419,422 ****
--- 420,438 ----
  			SETARG(codestr, i, (j^1));
  			codestr[i+3] = NOP;
+ 		
+ 		/* Replace LOAD_GLOBAL/LOAD_NAME None with LOAD_CONST None */
+ 		case LOAD_NAME:
+ 		case LOAD_GLOBAL:
+ 			j = GETARG(codestr, i);
+ 			name = PyString_AsString(PyTuple_GET_ITEM(names, j));
+ 			if (name == NULL  ||  strcmp(name, "None") != 0)
+ 				continue;
+ 			for (j=0 ; j < PyTuple_GET_SIZE(consts) ; j++) {
+ 				if (PyTuple_GET_ITEM(consts, j) == Py_None) {
+ 					codestr[i] = LOAD_CONST;
+ 					SETARG(codestr, i, j);
+ 					break;
+ 				}
+ 			}
  			break;
  
***************
*** 442,446 ****
  			if (!ISBASICBLOCK(blocks,i,6))
  				continue;
! 			if (GETARG(codestr, i) == 2 && \
  			    GETARG(codestr, i+3) == 2) {
  				codestr[i] = ROT_TWO;
--- 458,462 ----
  			if (!ISBASICBLOCK(blocks,i,6))
  				continue;
! 			if (GETARG(codestr, i) == 2 &&
  			    GETARG(codestr, i+3) == 2) {
  				codestr[i] = ROT_TWO;
***************
*** 451,455 ****
  				continue;
  			} 
! 			if (GETARG(codestr, i) == 3 && \
  			    GETARG(codestr, i+3) == 3) {
  				codestr[i] = ROT_THREE;
--- 467,471 ----
  				continue;
  			} 
! 			if (GETARG(codestr, i) == 3 &&
  			    GETARG(codestr, i+3) == 3) {
  				codestr[i] = ROT_THREE;
***************
*** 543,547 ****
  		co->co_stacksize = stacksize;
  		co->co_flags = flags;
! 		co->co_code = optimize_code(code, consts);
  		Py_INCREF(consts);
  		co->co_consts = consts;
--- 559,563 ----
  		co->co_stacksize = stacksize;
  		co->co_flags = flags;
! 		co->co_code = optimize_code(code, consts, names);
  		Py_INCREF(consts);
  		co->co_consts = consts;



More information about the Python-checkins mailing list