From e126f98658b2d0713506e4a7bfd437dec5f6ca9d Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Tue, 20 Dec 2016 16:07:18 +0900 Subject: Issue #29019: Fix dict.fromkeys(x) overallocates when x is sparce dict. Original patch by Rasmus Villemoes. --- Misc/NEWS | 3 +++ Objects/dictobject.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index eba6979..e203a2d 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 e3e4765..ebd352d 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; } -- cgit v0.12