]> granicus.if.org Git - python/commitdiff
Issue #16562: Optimize dict equality testing.
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 2 Dec 2012 18:10:07 +0000 (19:10 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 2 Dec 2012 18:10:07 +0000 (19:10 +0100)
Patch by Serhiy Storchaka (reviewed by Martin and Raymond).

Misc/NEWS
Objects/dictobject.c

index b37a3c7a21d80792cae6ef8ebc77fb37fa977799..f66354447df021e6777e9f4efb01f65302ff80c9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.4.0 Alpha 1?
 Core and Builtins
 -----------------
 
+- Issue #16562: Optimize dict equality testing.  Patch by Serhiy Storchaka.
+
 - Issue #16588: Silence unused-but-set warnings in Python/thread_pthread
 
 - Issue #16592: stringlib_bytes_join doesn't raise MemoryError on allocation
index f4ad3dccd48eabc279923ae1b63b4c1dbaa51cf4..a3c640939db62b6fb03000f8412a6dd58ef792ad 100644 (file)
@@ -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);