]> granicus.if.org Git - python/commitdiff
SF patch #729395: Dictionary tuning
authorRaymond Hettinger <python@rcn.com>
Wed, 7 May 2003 00:49:40 +0000 (00:49 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 7 May 2003 00:49:40 +0000 (00:49 +0000)
Adjust resize argument for dict.update() and dict.copy().
Extends the previous change to dict.__setitem__().

Objects/dictobject.c

index f3adc0bfdc085aaf496def9fba68fc4ce2d3d83e..c4959ff8e78ab8aa80004300999ee7538e4e0639 100644 (file)
@@ -1151,7 +1151,7 @@ PyDict_Merge(PyObject *a, PyObject *b, int override)
                 * that there will be no (or few) overlapping keys.
                 */
                if ((mp->ma_fill + other->ma_used)*3 >= (mp->ma_mask+1)*2) {
-                  if (dictresize(mp, (mp->ma_used + other->ma_used)*3/2) != 0)
+                  if (dictresize(mp, (mp->ma_used + other->ma_used)*2) != 0)
                           return -1;
                }
                for (i = 0; i <= other->ma_mask; i++) {
@@ -1236,7 +1236,7 @@ PyDict_Copy(PyObject *o)
        if (copy == NULL)
                return NULL;
        if (mp->ma_used > 0) {
-               if (dictresize(copy, mp->ma_used*3/2) != 0)
+               if (dictresize(copy, mp->ma_used*2) != 0)
                        return NULL;
                for (i = 0; i <= mp->ma_mask; i++) {
                        entry = &mp->ma_table[i];