summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2016-10-27 19:26:50 +0900
committerINADA Naoki <songofacandy@gmail.com>2016-10-27 19:26:50 +0900
commit44e775d28bc13b9827bdca924ac0a2a3342bc2e2 (patch)
tree4ce4c80201cdb624e8547b3778cfb4bf57aae626 /Objects
parentcd33ffe11d823efdf8254a7f5447208ee6963f48 (diff)
downloadcpython-44e775d28bc13b9827bdca924ac0a2a3342bc2e2.tar.gz
Issue #28509: dict.update() no longer allocate unnecessary large memory
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dictobject.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 03c973be63..9f98f68135 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;