diff options
author | Raymond Hettinger <python@rcn.com> | 2004-03-07 07:31:06 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-03-07 07:31:06 (GMT) |
commit | dd80f762650f42f5f9ae820d9f55b21ed6f33bc0 (patch) | |
tree | f7e7e6545b9896601dd13a1c07e409fef88ede2b /Python | |
parent | bff63f034366b0cf0442e9db5e5674751beca25a (diff) | |
download | cpython-dd80f762650f42f5f9ae820d9f55b21ed6f33bc0.zip cpython-dd80f762650f42f5f9ae820d9f55b21ed6f33bc0.tar.gz cpython-dd80f762650f42f5f9ae820d9f55b21ed6f33bc0.tar.bz2 |
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.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 9 | ||||
-rw-r--r-- | Python/compile.c | 4 |
2 files changed, 10 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 3371844..b20934c 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1225,6 +1225,15 @@ eval_frame(PyFrameObject *f) if (x != NULL) continue; 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(); v = TOP(); diff --git a/Python/compile.c b/Python/compile.c index 04d8b65..f58fb83 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1552,8 +1552,7 @@ com_list_iter(struct compiling *c, 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_list_comprehension(struct compiling *c, node *n) 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); |