From: INADA Naoki Date: Tue, 20 Dec 2016 07:07:18 +0000 (+0900) Subject: Issue #29019: Fix dict.fromkeys(x) overallocates when x is sparce dict. X-Git-Tag: v2.7.14rc1~329 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e126f98658b2d0713506e4a7bfd437dec5f6ca9d;p=python Issue #29019: Fix dict.fromkeys(x) overallocates when x is sparce dict. Original patch by Rasmus Villemoes. --- diff --git a/Misc/NEWS b/Misc/NEWS index eba6979507..e203a2d56f 100644 --- 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. diff --git a/Objects/dictobject.c b/Objects/dictobject.c index e3e4765d0a..ebd352d8e0 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -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; }