Issue #29019: Fix dict.fromkeys(x) overallocates when x is sparce dict.

Original patch by Rasmus Villemoes.
This commit is contained in:
INADA Naoki 2016-12-20 16:07:18 +09:00
parent a535d68ba7
commit e126f98658
2 changed files with 4 additions and 1 deletions

View File

@ -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.

View 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;
}