From: Raymond Hettinger Date: Wed, 13 May 2015 10:13:28 +0000 (-0700) Subject: Issue #23971: Fix underestimated presizing in dict.fromkeys() X-Git-Tag: v2.7.11rc1~302^2~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=77b3ae5e2cfdd7ddacf320dc295f2518c79860e7;p=thirdparty%2FPython%2Fcpython.git Issue #23971: Fix underestimated presizing in dict.fromkeys() --- diff --git a/Misc/NEWS b/Misc/NEWS index 39de4205de69..bd20dba2fa09 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -25,6 +25,8 @@ Core and Builtins - Issue #20274: When calling a _sqlite.Connection, it now complains if passed any keyword arguments. Previously it silently ignored them. +- Issue #23971: Fix underestimated presizing in dict.fromkeys(). + - Issue #20274: Remove ignored and erroneous "kwargs" parameters from three METH_VARARGS methods on _sqlite.Connection. diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 39e703590103..50afa3f654a8 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1361,7 +1361,7 @@ dict_fromkeys(PyObject *cls, PyObject *args) PyObject *key; long hash; - if (dictresize(mp, Py_SIZE(seq))) { + if (dictresize(mp, Py_SIZE(seq) / 2 * 3)) { Py_DECREF(d); return NULL; } @@ -1382,7 +1382,7 @@ dict_fromkeys(PyObject *cls, PyObject *args) PyObject *key; long hash; - if (dictresize(mp, PySet_GET_SIZE(seq))) { + if (dictresize(mp, PySet_GET_SIZE(seq) / 2 * 3)) { Py_DECREF(d); return NULL; }