]> granicus.if.org Git - python/commitdiff
Issue #29019: Fix dict.fromkeys(x) overallocates when x is sparce dict.
authorINADA Naoki <songofacandy@gmail.com>
Tue, 20 Dec 2016 07:07:18 +0000 (16:07 +0900)
committerINADA Naoki <songofacandy@gmail.com>
Tue, 20 Dec 2016 07:07:18 +0000 (16:07 +0900)
Original patch by Rasmus Villemoes.

Misc/NEWS
Objects/dictobject.c

index eba6979507e085720e67ca0f842ff9ec25f4ee40..e203a2d56ff9021e22733f136468b56b500ba5b2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #29019: Fix dict.fromkeys(x) overallocates when x is sparce dict.
+  Original patch by Rasmus Villemoes.
+
 - Issue #19542: Fix bugs in WeakValueDictionary.setdefault() and
   WeakValueDictionary.pop() when a GC collection happens in another
   thread.
index e3e4765d0a19c71d0686fb93537ac8d5204f2229..ebd352d8e04925a6401dd2a87caf4fe40da5c187 100644 (file)
@@ -1391,7 +1391,7 @@ dict_fromkeys(PyObject *cls, PyObject *args)
             PyObject *key;
             long hash;
 
-            if (dictresize(mp, Py_SIZE(seq) / 2 * 3)) {
+            if (dictresize(mp, ((PyDictObject *)seq)->ma_used / 2 * 3)) {
                 Py_DECREF(d);
                 return NULL;
             }