[Python-checkins] python/dist/src/Objects setobject.c,1.53,1.54

rhettinger@users.sourceforge.net rhettinger at users.sourceforge.net
Wed Aug 17 14:27:31 CEST 2005


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2350

Modified Files:
	setobject.c 
Log Message:
Add shortcuts for a|a and a&a.

Index: setobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/setobject.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- setobject.c	17 Aug 2005 00:27:42 -0000	1.53
+++ setobject.c	17 Aug 2005 12:27:17 -0000	1.54
@@ -1065,6 +1065,8 @@
 	result = (PySetObject *)set_copy(so);
 	if (result == NULL)
 		return NULL;
+	if ((PyObject *)so == other)
+		return (PyObject *)result;
 	if (set_update_internal(result, other) == -1) {
 		Py_DECREF(result);
 		return NULL;
@@ -1106,10 +1108,8 @@
 	PySetObject *result;
 	PyObject *key, *it, *tmp;
 
-	if ((PyObject *)so == other) {
-		Py_INCREF(other);
-		return other;
-	}
+	if ((PyObject *)so == other)
+		return set_copy(so);
 
 	result = (PySetObject *)make_new_set(so->ob_type, NULL);
 	if (result == NULL)
@@ -2062,13 +2062,14 @@
 	Py_DECREF(f);
 
 	/* Raise KeyError when popping from an empty set */
-	set_clear_internal(so);
+	assert(PyNumber_InPlaceSubtract(ob, ob) == ob);
+	Py_DECREF(ob);
 	assert(PySet_GET_SIZE(ob) == 0);
 	assertRaises(PySet_Pop(ob) == NULL, PyExc_KeyError);
 
-	/* Restore the set from the copy and use the abstract API */
-	assert(PyObject_CallMethod(ob, "update", "O", dup) == Py_None);
-	Py_DECREF(Py_None);
+	/* Restore the set from the copy using the PyNumber API */
+	assert(PyNumber_InPlaceOr(ob, dup) == ob);
+	Py_DECREF(ob);
 
 	/* Verify constructors accept NULL arguments */
 	f = PySet_New(NULL);



More information about the Python-checkins mailing list