Skip to content

Commit 6067d4b

Browse files
authored
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.
1 parent 5b956ca commit 6067d4b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Objects/dictobject.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,9 @@ _PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key)
14921492
kv = _PyUnicode_FromId(key); /* borrowed */
14931493
if (kv == NULL)
14941494
return NULL;
1495-
return PyDict_GetItemWithError(dp, kv);
1495+
Py_hash_t hash = ((PyASCIIObject *) kv)->hash;
1496+
assert (hash != -1); /* interned strings have their hash value initialised */
1497+
return _PyDict_GetItem_KnownHash(dp, kv, hash);
14961498
}
14971499

14981500
PyObject *

0 commit comments

Comments
 (0)