Commit ce5179fc authored by Raymond Hettinger's avatar Raymond Hettinger

Issue #23601: Use small object allocator for dict key objects

parent 89e54338
...@@ -18,6 +18,9 @@ Core and Builtins ...@@ -18,6 +18,9 @@ Core and Builtins
by external AST optimizers, but the compiler does not emit directly such by external AST optimizers, but the compiler does not emit directly such
node. node.
- Issue #23601: Sped-up allocation of dict key objects by using Python's
small object allocator. (Contributed by Julian Taylor.)
- Issue #18018: Import raises ImportError instead of SystemError if a relative - Issue #18018: Import raises ImportError instead of SystemError if a relative
import is attempted without a known parent package. import is attempted without a known parent package.
......
...@@ -324,7 +324,7 @@ static PyDictKeysObject *new_keys_object(Py_ssize_t size) ...@@ -324,7 +324,7 @@ static PyDictKeysObject *new_keys_object(Py_ssize_t size)
assert(size >= PyDict_MINSIZE_SPLIT); assert(size >= PyDict_MINSIZE_SPLIT);
assert(IS_POWER_OF_2(size)); assert(IS_POWER_OF_2(size));
dk = PyMem_MALLOC(sizeof(PyDictKeysObject) + dk = PyObject_MALLOC(sizeof(PyDictKeysObject) +
sizeof(PyDictKeyEntry) * (size-1)); sizeof(PyDictKeyEntry) * (size-1));
if (dk == NULL) { if (dk == NULL) {
PyErr_NoMemory(); PyErr_NoMemory();
...@@ -353,7 +353,7 @@ free_keys_object(PyDictKeysObject *keys) ...@@ -353,7 +353,7 @@ free_keys_object(PyDictKeysObject *keys)
Py_XDECREF(entries[i].me_key); Py_XDECREF(entries[i].me_key);
Py_XDECREF(entries[i].me_value); Py_XDECREF(entries[i].me_value);
} }
PyMem_FREE(keys); PyObject_FREE(keys);
} }
#define new_values(size) PyMem_NEW(PyObject *, size) #define new_values(size) PyMem_NEW(PyObject *, size)
...@@ -964,7 +964,7 @@ dictresize(PyDictObject *mp, Py_ssize_t minused) ...@@ -964,7 +964,7 @@ dictresize(PyDictObject *mp, Py_ssize_t minused)
} }
} }
assert(oldkeys->dk_refcnt == 1); assert(oldkeys->dk_refcnt == 1);
DK_DEBUG_DECREF PyMem_FREE(oldkeys); DK_DEBUG_DECREF PyObject_FREE(oldkeys);
} }
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment