]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40575: Avoid unnecessary overhead in _PyDict_GetItemIdWithError() (GH-20018)
authorscoder <stefan_ml@behnel.de>
Mon, 11 May 2020 04:04:31 +0000 (06:04 +0200)
committerGitHub <noreply@github.com>
Mon, 11 May 2020 04:04:31 +0000 (06:04 +0200)
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.

Objects/dictobject.c

index fa35d16478f63532a83d6d1dd0c7706ddd0b45d6..809a5ed778737003d590da8708c0331f4c6ad59c 100644 (file)
@@ -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 *