summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-12-18 18:26:18 +0000
committerRaymond Hettinger <python@rcn.com>2007-12-18 18:26:18 +0000
commiteffde12f5fe41bab9c27269bd77237200d953afd (patch)
treeb2eeab007ae8d329366ca815e1f1b3b3072415e9 /Python/compile.c
parenteb103b357780ecc9395cc680ebd4f5d436bbe888 (diff)
downloadcpython-git-effde12f5fe41bab9c27269bd77237200d953afd.tar.gz
Speed-up dictionary constructor by about 10%.
New opcode, STORE_MAP saves the compiler from awkward stack manipulations and specializes for dicts using PyDict_SetItem instead of PyObject_SetItem. Old disassembly: 0 BUILD_MAP 0 3 DUP_TOP 4 LOAD_CONST 1 (1) 7 ROT_TWO 8 LOAD_CONST 2 ('x') 11 STORE_SUBSCR 12 DUP_TOP 13 LOAD_CONST 3 (2) 16 ROT_TWO 17 LOAD_CONST 4 ('y') 20 STORE_SUBSCR New disassembly: 0 BUILD_MAP 0 3 LOAD_CONST 1 (1) 6 LOAD_CONST 2 ('x') 9 STORE_MAP 10 LOAD_CONST 3 (2) 13 LOAD_CONST 4 ('y') 16 STORE_MAP
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 193d52076a..3b0c53fb19 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -729,6 +729,8 @@ opcode_stack_effect(int opcode, int oparg)
return -1;
case STORE_SUBSCR:
return -3;
+ case STORE_MAP:
+ return -2;
case DELETE_SUBSCR:
return -2;
@@ -2926,13 +2928,11 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
/* We must arrange things just right for STORE_SUBSCR.
It wants the stack to look like (value) (dict) (key) */
for (i = 0; i < n; i++) {
- ADDOP(c, DUP_TOP);
VISIT(c, expr,
(expr_ty)asdl_seq_GET(e->v.Dict.values, i));
- ADDOP(c, ROT_TWO);
VISIT(c, expr,
(expr_ty)asdl_seq_GET(e->v.Dict.keys, i));
- ADDOP(c, STORE_SUBSCR);
+ ADDOP(c, STORE_MAP);
}
break;
case ListComp_kind: