[Python-checkins] python/dist/src/Python ceval.c, 2.378, 2.379 compile.c, 2.298, 2.299

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sun Mar 7 02:31:08 EST 2004


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

Modified Files:
	ceval.c compile.c 
Log Message:
SF patch #910929:  Optimize list comprehensions

Add a new opcode, LIST_APPEND, and apply it to the code generation for
list comprehensions.  Reduces the per-loop overhead by about a third.



Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.378
retrieving revision 2.379
diff -C2 -d -r2.378 -r2.379
*** ceval.c	1 Mar 2004 15:44:05 -0000	2.378
--- ceval.c	7 Mar 2004 07:31:05 -0000	2.379
***************
*** 1226,1229 ****
--- 1226,1238 ----
  			break;
  
+ 		case LIST_APPEND:
+ 			w = POP();
+ 			v = POP();
+ 			err = PyList_Append(v, w);
+ 			Py_DECREF(v);
+ 			Py_DECREF(w);
+ 			if (err == 0) continue;
+ 			break;
+ 
  		case INPLACE_POWER:
  			w = POP();

Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.298
retrieving revision 2.299
diff -C2 -d -r2.298 -r2.299
*** compile.c	29 Nov 2003 23:52:13 -0000	2.298
--- compile.c	7 Mar 2004 07:31:06 -0000	2.299
***************
*** 1553,1558 ****
  		com_push(c, 1);
  		com_node(c, e);
! 		com_addoparg(c, CALL_FUNCTION, 1);
! 		com_addbyte(c, POP_TOP);
  		com_pop(c, 2);
  	}
--- 1553,1557 ----
  		com_push(c, 1);
  		com_node(c, e);
! 		com_addbyte(c, LIST_APPEND);
  		com_pop(c, 2);
  	}
***************
*** 1570,1574 ****
  	com_addbyte(c, DUP_TOP); /* leave the result on the stack */
  	com_push(c, 2);
- 	com_addop_name(c, LOAD_ATTR, "append");
  	com_addop_varname(c, VAR_STORE, tmpname);
  	com_pop(c, 1);
--- 1569,1572 ----




More information about the Python-checkins mailing list