]> granicus.if.org Git - python/commitdiff
Issue #28509: dict.update() no longer allocate unnecessary large memory
authorINADA Naoki <songofacandy@gmail.com>
Thu, 27 Oct 2016 10:26:50 +0000 (19:26 +0900)
committerINADA Naoki <songofacandy@gmail.com>
Thu, 27 Oct 2016 10:26:50 +0000 (19:26 +0900)
Misc/NEWS
Objects/dictobject.c

index e47b977e2d4229323316988194de2a9a82348636..a6b340f4d599cf4cc701d73794497f8cb9c08532 100644 (file)
--- 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.
 
index 03c973be636adc05cba13d469203a5a64a67c35d..9f98f6813518982928622c970510fa8389125ecf 100644 (file)
@@ -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;