summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-12-02 18:10:07 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-12-02 18:10:07 (GMT)
commit0e9958b543686ccd39d7fceb7de2ac84fff83834 (patch)
tree3e4211729f461d70af6419aa81fb41d2f72d9e67 /Objects/dictobject.c
parent181e20a6fc178f97741eef1176f660ad5447ea8b (diff)
downloadcpython-0e9958b543686ccd39d7fceb7de2ac84fff83834.zip
cpython-0e9958b543686ccd39d7fceb7de2ac84fff83834.tar.gz
cpython-0e9958b543686ccd39d7fceb7de2ac84fff83834.tar.bz2
Issue #16562: Optimize dict equality testing.
Patch by Serhiy Storchaka (reviewed by Martin and Raymond).
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index f4ad3dc..a3c6409 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2114,13 +2114,18 @@ dict_equal(PyDictObject *a, PyDictObject *b)
if (aval != NULL) {
int cmp;
PyObject *bval;
+ PyObject **vaddr;
PyObject *key = ep->me_key;
/* temporarily bump aval's refcount to ensure it stays
alive until we're done with it */
Py_INCREF(aval);
/* ditto for key */
Py_INCREF(key);
- bval = PyDict_GetItemWithError((PyObject *)b, key);
+ /* reuse the known hash value */
+ if ((b->ma_keys->dk_lookup)(b, key, ep->me_hash, &vaddr) == NULL)
+ bval = NULL;
+ else
+ bval = *vaddr;
Py_DECREF(key);
if (bval == NULL) {
Py_DECREF(aval);