summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorscoder <stefan_ml@behnel.de>2020-05-11 04:04:31 (GMT)
committerGitHub <noreply@github.com>2020-05-11 04:04:31 (GMT)
commit6067d4bc3ce5ff4cfa5b47ceecc84a3941bc031c (patch)
tree3520bec8a7bddf3edfda8aa888306ee841f1eaac /Objects/dictobject.c
parent5b956ca42de37c761562e9c9aeb96a0e67606e33 (diff)
downloadcpython-6067d4bc3ce5ff4cfa5b47ceecc84a3941bc031c.zip
cpython-6067d4bc3ce5ff4cfa5b47ceecc84a3941bc031c.tar.gz
cpython-6067d4bc3ce5ff4cfa5b47ceecc84a3941bc031c.tar.bz2
bpo-40575: Avoid unnecessary overhead in _PyDict_GetItemIdWithError() (GH-20018)
Avoid unnecessary overhead in _PyDict_GetItemIdWithError() by calling _PyDict_GetItem_KnownHash() instead of the more generic PyDict_GetItemWithError(), since we already know the hash of interned strings.
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index fa35d16..809a5ed 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1492,7 +1492,9 @@ _PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key)
kv = _PyUnicode_FromId(key); /* borrowed */
if (kv == NULL)
return NULL;
- return PyDict_GetItemWithError(dp, kv);
+ Py_hash_t hash = ((PyASCIIObject *) kv)->hash;
+ assert (hash != -1); /* interned strings have their hash value initialised */
+ return _PyDict_GetItem_KnownHash(dp, kv, hash);
}
PyObject *