summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2019-03-12 08:25:44 (GMT)
committerGitHub <noreply@github.com>2019-03-12 08:25:44 (GMT)
commitf2a186712bfe726d54723eba37d80c7f0303a50b (patch)
tree66667f84b514c1550af31d16c58bc2724aa514b1 /Objects/dictobject.c
parentfc06a192fdc44225ef1cc879f615a81931ad0a85 (diff)
downloadcpython-f2a186712bfe726d54723eba37d80c7f0303a50b.zip
cpython-f2a186712bfe726d54723eba37d80c7f0303a50b.tar.gz
cpython-f2a186712bfe726d54723eba37d80c7f0303a50b.tar.bz2
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().
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 83cadda..108c612 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -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.