diff options
author | Raymond Hettinger <python@rcn.com> | 2007-12-18 18:26:18 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2007-12-18 18:26:18 +0000 |
commit | effde12f5fe41bab9c27269bd77237200d953afd (patch) | |
tree | b2eeab007ae8d329366ca815e1f1b3b3072415e9 /Python/ceval.c | |
parent | eb103b357780ecc9395cc680ebd4f5d436bbe888 (diff) | |
download | cpython-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/ceval.c')
-rw-r--r-- | Python/ceval.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index d74d017996..1af998d777 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2002,6 +2002,18 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) if (x != NULL) continue; break; + case STORE_MAP: + w = TOP(); /* key */ + u = SECOND(); /* value */ + v = THIRD(); /* dict */ + STACKADJ(-2); + assert (PyDict_CheckExact(v)); + err = PyDict_SetItem(v, w, u); /* v[w] = u */ + Py_DECREF(u); + Py_DECREF(w); + if (err == 0) continue; + break; + case LOAD_ATTR: w = GETITEM(names, oparg); v = TOP(); |