mirror of
https://github.com/python/cpython.git
synced 2025-07-27 13:14:41 +00:00
Give meaning to the oparg for BUILD_MAP: estimated size of the dictionary.
Allows dictionaries to be pre-sized (upto 255 elements) saving time lost to re-sizes with their attendant mallocs and re-insertions. Has zero effect on small dictionaries (5 elements or fewer), a slight benefit for dicts upto 22 elements (because they had to resize once anyway), and more benefit for dicts upto 255 elements (saving multiple resizes during the build-up and reducing the number of collisions on the first insertions). Beyond 255 elements, there is no addional benefit.
This commit is contained in:
parent
3c887b2802
commit
fd7ed407d7
6 changed files with 26 additions and 6 deletions
|
@ -1997,7 +1997,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
|||
break;
|
||||
|
||||
case BUILD_MAP:
|
||||
x = PyDict_New();
|
||||
x = _PyDict_NewPresized((Py_ssize_t)oparg);
|
||||
PUSH(x);
|
||||
if (x != NULL) continue;
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue