summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2016-10-27 10:26:50 (GMT)
committerINADA Naoki <songofacandy@gmail.com>2016-10-27 10:26:50 (GMT)
commitb1152be2def8d4073cbb0ac3c05aed88d5e8360f (patch)
tree3859dcbcbd5350fb476dad3633fbe43054a36bd0
parentec9357b90c00760cfdc019b499fdf63bc98124ae (diff)
downloadcpython-b1152be2def8d4073cbb0ac3c05aed88d5e8360f.zip
cpython-b1152be2def8d4073cbb0ac3c05aed88d5e8360f.tar.gz
cpython-b1152be2def8d4073cbb0ac3c05aed88d5e8360f.tar.bz2
Issue #28509: dict.update() no longer allocate unnecessary large memory
-rw-r--r--Misc/NEWS2
-rw-r--r--Objects/dictobject.c6
2 files changed, 6 insertions, 2 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index e47b977..a6b340f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.6.0 beta 3
Core and Builtins
-----------------
+- Issue #28509: dict.update() no longer allocate unnecessary large memory.
+
- Issue #28426: Fixed potential crash in PyUnicode_AsDecodedObject() in debug
build.
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 03c973b..9f98f68 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2406,9 +2406,11 @@ dict_merge(PyObject *a, PyObject *b, int override)
* incrementally resizing as we insert new items. Expect
* that there will be no (or few) overlapping keys.
*/
- if (mp->ma_keys->dk_usable * 3 < other->ma_used * 2)
- if (dictresize(mp, (mp->ma_used + other->ma_used)*2) != 0)
+ if (USABLE_FRACTION(mp->ma_keys->dk_size) < other->ma_used) {
+ if (dictresize(mp, ESTIMATE_SIZE(mp->ma_used + other->ma_used))) {
return -1;
+ }
+ }
ep0 = DK_ENTRIES(other->ma_keys);
for (i = 0, n = other->ma_keys->dk_nentries; i < n; i++) {
PyObject *key, *value;