From: Raymond Hettinger Date: Sat, 14 May 2005 18:08:25 +0000 (+0000) Subject: SF patch #1200051: Small optimization for PyDict_Merge() X-Git-Tag: v2.5a0~1786 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=186e739d2996270c6a30d76e94193921fccfc2f5;p=thirdparty%2FPython%2Fcpython.git SF patch #1200051: Small optimization for PyDict_Merge() (Contributed by Barry Warsaw and Matt Messier.) --- diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 1be34774e3e3..aaca5aa4c1da 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.