[Python-checkins] cpython (2.7): Issue #23971: Fix underestimated presizing in dict.fromkeys()

raymond.hettinger python-checkins at python.org
Wed May 13 12:13:34 CEST 2015


https://hg.python.org/cpython/rev/cd0706499812
changeset:   96019:cd0706499812
branch:      2.7
user:        Raymond Hettinger <python at rcn.com>
date:        Wed May 13 03:13:28 2015 -0700
summary:
  Issue #23971:  Fix underestimated presizing in dict.fromkeys()

files:
  Misc/NEWS            |  2 ++
  Objects/dictobject.c |  4 ++--
  2 files changed, 4 insertions(+), 2 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,8 @@
 - 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
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1361,7 +1361,7 @@
             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 @@
             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;
             }

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list