mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-30040: new empty dict uses key-sharing dict (GH-1080)
Sizeof new empty dict becomes 72 bytes from 240 bytes (amd64). It is same size to empty dict created by dict.clear().
This commit is contained in:
parent
fc06a192fd
commit
f2a186712b
4 changed files with 13 additions and 8 deletions
|
@ -691,10 +691,8 @@ clone_combined_dict(PyDictObject *orig)
|
|||
PyObject *
|
||||
PyDict_New(void)
|
||||
{
|
||||
PyDictKeysObject *keys = new_keys_object(PyDict_MINSIZE);
|
||||
if (keys == NULL)
|
||||
return NULL;
|
||||
return new_dict(keys, NULL);
|
||||
dictkeys_incref(Py_EMPTY_KEYS);
|
||||
return new_dict(Py_EMPTY_KEYS, empty_values);
|
||||
}
|
||||
|
||||
/* Search index of hash table from offset of entry table */
|
||||
|
@ -1276,6 +1274,9 @@ _PyDict_NewPresized(Py_ssize_t minused)
|
|||
Py_ssize_t newsize;
|
||||
PyDictKeysObject *new_keys;
|
||||
|
||||
if (minused == 0) {
|
||||
return PyDict_New();
|
||||
}
|
||||
/* There are no strict guarantee that returned dict can contain minused
|
||||
* items without resize. So we create medium size dict instead of very
|
||||
* large dict or MemoryError.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue