Skip to content

Commit

Permalink
bpo-40575: Avoid unnecessary overhead in _PyDict_GetItemIdWithError() (
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
scoder authored May 11, 2020
1 parent 5b956ca commit 6067d4b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down

0 comments on commit 6067d4b

Please sign in to comment.