mirror of
https://github.com/python/cpython.git
synced 2025-12-11 11:31:05 +00:00
SF patch #1200051: Small optimization for PyDict_Merge()
(Contributed by Barry Warsaw and Matt Messier.)
This commit is contained in:
parent
0f43983aa3
commit
186e739d29
1 changed files with 6 additions and 0 deletions
|
|
@ -1203,6 +1203,12 @@ PyDict_Merge(PyObject *a, PyObject *b, int override)
|
||||||
if (other == mp || other->ma_used == 0)
|
if (other == mp || other->ma_used == 0)
|
||||||
/* a.update(a) or a.update({}); nothing to do */
|
/* a.update(a) or a.update({}); nothing to do */
|
||||||
return 0;
|
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
|
/* Do one big resize at the start, rather than
|
||||||
* incrementally resizing as we insert new items. Expect
|
* incrementally resizing as we insert new items. Expect
|
||||||
* that there will be no (or few) overlapping keys.
|
* that there will be no (or few) overlapping keys.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue