Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-40575: 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 committed May 9, 2020
commit 7271ad8524e5adda7422f3ed69a91bd53badac39
5 changes: 4 additions & 1 deletion Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,11 +1488,14 @@ PyDict_GetItemWithError(PyObject *op, PyObject *key)
PyObject *
_PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key)
{
Py_hash_t hash;
Comment thread
scoder marked this conversation as resolved.
Outdated
PyObject *kv;
kv = _PyUnicode_FromId(key); /* borrowed */
if (kv == NULL)
return NULL;
return PyDict_GetItemWithError(dp, kv);
hash = ((PyASCIIObject *) kv)->hash;
Comment thread
scoder marked this conversation as resolved.
Outdated
assert (hash != -1); /* interned strings have their hash value initialised */
return _PyDict_GetItem_KnownHash(dp, kv, hash);
}

PyObject *
Expand Down