summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-05-14 18:08:25 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-05-14 18:08:25 (GMT)
commit186e739d2996270c6a30d76e94193921fccfc2f5 (patch)
treecd1ef27fb34227bfe29dcb710e5971d15b87927a /Objects/dictobject.c
parent0f43983aa3dd5a7f5a6fa3cac219293d5f3b066d (diff)
downloadcpython-186e739d2996270c6a30d76e94193921fccfc2f5.zip
cpython-186e739d2996270c6a30d76e94193921fccfc2f5.tar.gz
cpython-186e739d2996270c6a30d76e94193921fccfc2f5.tar.bz2
SF patch #1200051: Small optimization for PyDict_Merge()
(Contributed by Barry Warsaw and Matt Messier.)
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 1be3477..aaca5aa 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1203,6 +1203,12 @@ PyDict_Merge(PyObject *a, PyObject *b, int override)
if (other == mp || other->ma_used == 0)
/* a.update(a) or a.update({}); nothing to do */
return 0;
+ if (mp->ma_used == 0)
+ /* Since the target dict is empty, PyDict_GetItem()
+ * always returns NULL. Setting override to 1
+ * skips the unnecessary test.
+ */
+ override = 1;
/* Do one big resize at the start, rather than
* incrementally resizing as we insert new items. Expect
* that there will be no (or few) overlapping keys.