summaryrefslogtreecommitdiffstats
path: root/Objects/setobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-02-19 20:44:04 (GMT)
committerRaymond Hettinger <python@rcn.com>2007-02-19 20:44:04 (GMT)
commit15cade0568f5028c9508c480e5d8fb9166e71f0e (patch)
tree365c10dd5012ec19e2ee2dd2164eac85f9bac2e0 /Objects/setobject.c
parentcbac8ce5b0394fe68329ac839a07474969dd7493 (diff)
downloadcpython-15cade0568f5028c9508c480e5d8fb9166e71f0e.zip
cpython-15cade0568f5028c9508c480e5d8fb9166e71f0e.tar.gz
cpython-15cade0568f5028c9508c480e5d8fb9166e71f0e.tar.bz2
Fixup set/dict interoperability.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r--Objects/setobject.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 1f06cee..07ba996 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -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;