From 0e9958b543686ccd39d7fceb7de2ac84fff83834 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 2 Dec 2012 19:10:07 +0100 Subject: Issue #16562: Optimize dict equality testing. Patch by Serhiy Storchaka (reviewed by Martin and Raymond). --- Misc/NEWS | 2 ++ Objects/dictobject.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index b37a3c7..f663544 100644 --- 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 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); -- cgit v0.12