[Python-checkins] r53829 - python/trunk/Objects/setobject.c

raymond.hettinger python-checkins at python.org
Mon Feb 19 21:44:06 CET 2007


Author: raymond.hettinger
Date: Mon Feb 19 21:44:04 2007
New Revision: 53829

Modified:
   python/trunk/Objects/setobject.c
Log:
Fixup set/dict interoperability.

Modified: python/trunk/Objects/setobject.c
==============================================================================
--- python/trunk/Objects/setobject.c	(original)
+++ python/trunk/Objects/setobject.c	Mon Feb 19 21:44:04 2007
@@ -919,7 +919,18 @@
 		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;
 


More information about the Python-checkins mailing list