]> granicus.if.org Git - python/commitdiff
Fixup set/dict interoperability.
authorRaymond Hettinger <python@rcn.com>
Mon, 19 Feb 2007 20:44:04 +0000 (20:44 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 19 Feb 2007 20:44:04 +0000 (20:44 +0000)
Objects/setobject.c

index 1f06cee5a11bfe03834007e43a65dfe5d4fe387e..07ba99641c38401052d15c1f76862d742ff332e9 100644 (file)
@@ -919,7 +919,18 @@ set_update_internal(PySetObject *so, PyObject *other)
                PyObject *value;
                Py_ssize_t pos = 0;
                long hash;
+               Py_ssize_t dictsize = PyDict_Size(other);
 
+               /* Do one big resize at the start, rather than
+               * incrementally resizing as we insert new keys.  Expect
+               * that there will be no (or few) overlapping keys.
+               */
+               if (dictsize == -1)
+                       return -1;
+               if ((so->fill + dictsize)*3 >= (so->mask+1)*2) {
+                       if (set_table_resize(so, (so->used + dictsize)*2) != 0)
+                               return -1;
+               }
                while (_PyDict_Next(other, &pos, &key, &value, &hash)) {
                        setentry an_entry;