Mercurial > cpython-lru_cache-weakref
comparison Python/import.c @ 44334:07aa19170a67 legacy-trunk
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
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Tue, 18 Dec 2007 18:26:18 +0000 |
| parents | 803edf9b1dd9 |
| children | 0cbe94bea2c7 |
comparison
equal
deleted
inserted
replaced
| 44333:56f342c84e87 | 44334:07aa19170a67 |
|---|---|
| 64 Python 2.5b3: 62101 (fix wrong code: for x, in ...) | 64 Python 2.5b3: 62101 (fix wrong code: for x, in ...) |
| 65 Python 2.5b3: 62111 (fix wrong code: x += yield) | 65 Python 2.5b3: 62111 (fix wrong code: x += yield) |
| 66 Python 2.5c1: 62121 (fix wrong lnotab with for loops and | 66 Python 2.5c1: 62121 (fix wrong lnotab with for loops and |
| 67 storing constants that should have been removed) | 67 storing constants that should have been removed) |
| 68 Python 2.5c2: 62131 (fix wrong code: for x, in ... in listcomp/genexp) | 68 Python 2.5c2: 62131 (fix wrong code: for x, in ... in listcomp/genexp) |
| 69 Python 2.6a0: 62141 (peephole optimizations) | 69 Python 2.6a0: 62151 (peephole optimizations and STORE_MAP opcode) |
| 70 . | 70 . |
| 71 */ | 71 */ |
| 72 #define MAGIC (62141 | ((long)'\r'<<16) | ((long)'\n'<<24)) | 72 #define MAGIC (62151 | ((long)'\r'<<16) | ((long)'\n'<<24)) |
| 73 | 73 |
| 74 /* Magic word as global; note that _PyImport_Init() can change the | 74 /* Magic word as global; note that _PyImport_Init() can change the |
| 75 value of this global to accommodate for alterations of how the | 75 value of this global to accommodate for alterations of how the |
| 76 compiler works which are enabled by command line switches. */ | 76 compiler works which are enabled by command line switches. */ |
| 77 static long pyc_magic = MAGIC; | 77 static long pyc_magic = MAGIC; |
