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

Lines changed: 3 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy