[Python-checkins] python/dist/src/Objects setobject.c,1.20,1.21

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Wed Dec 31 09:09:01 EST 2003


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv25420
Modified Files:
	setobject.c 
Log Message:
* Simplify and speedup logic for tp_print.
* Speed-up intersection whenever PyDict_Next can be used.
Index: setobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/setobject.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** setobject.c	15 Dec 2003 21:16:06 -0000	1.20
--- setobject.c	31 Dec 2003 14:08:58 -0000	1.21
***************
*** 241,245 ****
 {
 	PySetObject *result;
! 	PyObject *item, *selfdata, *tgtdata, *it;
 
 	result = (PySetObject *)make_new_set(so->ob_type, NULL);
--- 241,245 ----
 {
 	PySetObject *result;
! 	PyObject *item, *selfdata, *tgtdata, *it, *tmp;
 
 	result = (PySetObject *)make_new_set(so->ob_type, NULL);
***************
*** 249,260 ****
 	selfdata = so->data;
 
! 	if (PyAnySet_Check(other) && 
! 		PyDict_Size(((PySetObject *)other)->data) > PyDict_Size(selfdata)) {
! 		selfdata = ((PySetObject *)other)->data;
! 		other = (PyObject *)so;
! 	} else if (PyDict_Check(other) &&
! 		PyDict_Size(other) > PyDict_Size(selfdata)) {
 		selfdata = other;
! 		other = so->data;
 	}
 
--- 249,273 ----
 	selfdata = so->data;
 
! 	if (PyAnySet_Check(other))
! 		other = ((PySetObject *)other)->data;
! 
! 	if (PyDict_Check(other) && PyDict_Size(other) > PyDict_Size(selfdata)) {
! 		tmp = selfdata;
 		selfdata = other;
! 		other = tmp;
! 	}
! 
! 	if (PyDict_CheckExact(other)) {
! 		PyObject *value;
! 		int pos = 0;
! 		while (PyDict_Next(other, &pos, &item, &value)) {
! 			if (PyDict_Contains(selfdata, item)) {
! 				if (PyDict_SetItem(tgtdata, item, Py_True) == -1) {
! 					Py_DECREF(result);
! 					return NULL;
! 				}
! 			}
! 		}
! 		return (PyObject *)result;
 	}
 
***************
*** 720,735 ****
 {
 	PyObject *key, *value;
! 	int pos=0, firstpass=1;
 
 	fprintf(fp, "%s([", so->ob_type->tp_name);
 	while (PyDict_Next(so->data, &pos, &key, &value)) {
! 		if (firstpass)
! 			firstpass = 0;
! 		else
! 			fprintf(fp, ", ");
 		if (PyObject_Print(key, fp, 0) != 0)
 			return -1;
 	}
! 	fprintf(fp, "])");
 	return 0;
 }
--- 733,748 ----
 {
 	PyObject *key, *value;
! 	int pos=0;
! 	char *emit = "";	/* No separator emitted on first pass */
! 	char *separator = ", ";
 
 	fprintf(fp, "%s([", so->ob_type->tp_name);
 	while (PyDict_Next(so->data, &pos, &key, &value)) {
! 		fputs(emit, fp);
! 		emit = separator;
 		if (PyObject_Print(key, fp, 0) != 0)
 			return -1;
 	}
! 	fputs("])", fp);
 	return 0;
 }
***************
*** 1078,1082 ****
 	"frozenset",			/* tp_name */
 	sizeof(PySetObject),		/* tp_basicsize */
! 	0,				/* tp_itemsize */	/* methods */
 	(destructor)set_dealloc,	/* tp_dealloc */
 	(printfunc)set_tp_print,	/* tp_print */
--- 1091,1096 ----
 	"frozenset",			/* tp_name */
 	sizeof(PySetObject),		/* tp_basicsize */
! 	0,				/* tp_itemsize */
! 	/* methods */
 	(destructor)set_dealloc,	/* tp_dealloc */
 	(printfunc)set_tp_print,	/* tp_print */


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /