[Python-checkins] python/nondist/sandbox/set setobject.c,1.1,1.2

rhettinger@users.sourceforge.net rhettinger at users.sourceforge.net
Thu Jul 28 01:38:43 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/set
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12069

Modified Files:
	setobject.c 
Log Message:
Restore original intersection_update logic.

Index: setobject.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/set/setobject.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- setobject.c	22 Jul 2005 15:32:29 -0000	1.1
+++ setobject.c	27 Jul 2005 23:38:40 -0000	1.2
@@ -1009,41 +1009,53 @@
 \n\
 (i.e. all elements that are in both sets.)");
 
+
+static void
+set_swap_bodys(PySetObject *a, PySetObject *b)
+{
+	int t;
+	PySetEntry *u;
+	PySetEntry *(*f)(PySetObject *mp, PyObject *key, long hash);
+	PySetEntry tab[PySet_MINSIZE];
+	long h;
+
+	t = a->ma_fill;     a->ma_fill   = b->ma_fill;        b->ma_fill  = t;
+	t = a->ma_used;     a->ma_used   = b->ma_used;        b->ma_used  = t;
+	t = a->ma_mask;     a->ma_mask   = b->ma_mask;        b->ma_mask  = t;
+
+	u = a->ma_table;
+	if (a->ma_table == a->ma_smalltable)
+		u = b->ma_smalltable;
+	a->ma_table  = b->ma_table;
+	if (b->ma_table == b->ma_smalltable)
+		a->ma_table = a->ma_smalltable;
+	b->ma_table = u;
+
+	f = a->ma_lookup;   a->ma_lookup = b->ma_lookup;      b->ma_lookup = f;
+
+	if (a->ma_table == a->ma_smalltable || b->ma_table == b->ma_smalltable) {
+		memcpy(tab, a->ma_smalltable, sizeof(tab));
+		memcpy(a->ma_smalltable, b->ma_smalltable, sizeof(tab));
+		memcpy(b->ma_smalltable, tab, sizeof(tab));
+	}
+
+	h = a->hash;        a->hash      = b->hash;           b->hash     = h;
+}
+
 static PyObject *set_clear(PySetObject *so); /// XXX remove forward declaration
 static int set_tp_clear(PySetObject *so); /// XXX remove forward declaration
 
 static PyObject *
 set_intersection_update(PySetObject *so, PyObject *other)
 {
-/*	// Hmm, this made the timings slower
-	PyObject *tmp, *key;
-	int pos = 0;
+	PyObject *tmp;
 
 	tmp = set_intersection(so, other);
 	if (tmp == NULL)
 		return NULL;
-
-	while (set_next_internal(so, &pos, &key)) {
-		if (!set_contains_internal((PySetObject *)tmp, key)) {
-			if (set_remove_internal(so, key) == -1) {
-				Py_DECREF(tmp);
-				return NULL;
-			}
-		}
-	}
+	set_swap_bodys(so, (PySetObject *)tmp);
 	Py_DECREF(tmp);
 	Py_RETURN_NONE;
-*/
-
-	PyObject *tmp, *rv;
-
-	tmp = set_intersection(so, other);
-	if (tmp == NULL)
-		return NULL;
-	set_tp_clear(so);
-	rv = set_update(so, tmp);
-	Py_DECREF(tmp);
-	return rv;
 }
 
 PyDoc_STRVAR(intersection_update_doc,



More information about the Python-checkins mailing list