diff Python/compile.c @ 31618:bc006682acb2 legacy-trunk

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.
author Raymond Hettinger <python@rcn.com>
date Sun, 07 Mar 2004 07:31:06 +0000
parents 9c846c3df6f3
children 6509354e7876
line wrap: on
line diff
--- a/Python/compile.c	Fri Mar 05 14:33:21 2004 +0000
+++ b/Python/compile.c	Sun Mar 07 07:31:06 2004 +0000
@@ -1552,8 +1552,7 @@
 		com_addop_varname(c, VAR_LOAD, t);
 		com_push(c, 1);
 		com_node(c, e);
-		com_addoparg(c, CALL_FUNCTION, 1);
-		com_addbyte(c, POP_TOP);
+		com_addbyte(c, LIST_APPEND);
 		com_pop(c, 2);
 	}
 }
@@ -1569,7 +1568,6 @@
 	com_addoparg(c, BUILD_LIST, 0);
 	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);
 	com_list_for(c, CHILD(n, 1), CHILD(n, 0), tmpname);