[Python-checkins] python/dist/src/Objects dictobject.c, 2.147, 2.148 setobject.c, 1.13, 1.14

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Tue Nov 25 16:12:16 EST 2003


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv24958/Objects

Modified Files:
	dictobject.c setobject.c 
Log Message:
Expose dict_contains() and PyDict_Contains() with is about 10% faster
than PySequence_Contains() and more clearly applicable to dicts.

Apply the new function in setobject.c where __contains__ checking is
ubiquitous.



Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.147
retrieving revision 2.148
diff -C2 -d -r2.147 -r2.148
*** dictobject.c	1 Sep 2003 22:12:08 -0000	2.147
--- dictobject.c	25 Nov 2003 21:12:14 -0000	2.148
***************
*** 1815,1822 ****
  };
  
! static int
! dict_contains(dictobject *mp, PyObject *key)
  {
  	long hash;
  
  	if (!PyString_CheckExact(key) ||
--- 1815,1823 ----
  };
  
! int
! PyDict_Contains(PyObject *op, PyObject *key)
  {
  	long hash;
+ 	dictobject *mp = (dictobject *)op;
  
  	if (!PyString_CheckExact(key) ||
***************
*** 1838,1842 ****
  	0,					/* sq_ass_item */
  	0,					/* sq_ass_slice */
! 	(objobjproc)dict_contains,		/* sq_contains */
  	0,					/* sq_inplace_concat */
  	0,					/* sq_inplace_repeat */
--- 1839,1843 ----
  	0,					/* sq_ass_item */
  	0,					/* sq_ass_slice */
! 	(objobjproc)PyDict_Contains,		/* sq_contains */
  	0,					/* sq_inplace_concat */
  	0,					/* sq_inplace_repeat */

Index: setobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/setobject.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** setobject.c	24 Nov 2003 22:18:49 -0000	1.13
--- setobject.c	25 Nov 2003 21:12:14 -0000	1.14
***************
*** 144,148 ****
  	int result;
  
! 	result = PySequence_Contains(so->data, key);
  	if (result == -1 && PyAnySet_Check(key)) {
  		PyErr_Clear();
--- 144,148 ----
  	int result;
  
! 	result = PyDict_Contains(so->data, key);
  	if (result == -1 && PyAnySet_Check(key)) {
  		PyErr_Clear();
***************
*** 150,154 ****
  		if (tmp == NULL)
  			return -1;
! 		result = PySequence_Contains(so->data, tmp);
  		Py_DECREF(tmp);
  	}
--- 150,154 ----
  		if (tmp == NULL)
  			return -1;
! 		result = PyDict_Contains(so->data, tmp);
  		Py_DECREF(tmp);
  	}
***************
*** 253,257 ****
  
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (PySequence_Contains(selfdata, item)) {
  			if (PyDict_SetItem(tgtdata, item, Py_True) == -1) {
  				Py_DECREF(it);
--- 253,257 ----
  
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (PyDict_Contains(selfdata, item)) {
  			if (PyDict_SetItem(tgtdata, item, Py_True) == -1) {
  				Py_DECREF(it);
***************
*** 293,297 ****
  	selfdata = so->data;
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (PySequence_Contains(selfdata, item)) {
  			if (PyDict_SetItem(newdict, item, Py_True) == -1) {
  				Py_DECREF(newdict);
--- 293,297 ----
  	selfdata = so->data;
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (PyDict_Contains(selfdata, item)) {
  			if (PyDict_SetItem(newdict, item, Py_True) == -1) {
  				Py_DECREF(newdict);
***************
*** 376,380 ****
  
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (!PySequence_Contains(otherdata, item)) {
  			if (PyDict_SetItem(tgtdata, item, Py_True) == -1) {
  				Py_XDECREF(otherset);
--- 376,380 ----
  
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (!PyDict_Contains(otherdata, item)) {
  			if (PyDict_SetItem(tgtdata, item, Py_True) == -1) {
  				Py_XDECREF(otherset);
***************
*** 482,486 ****
  
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (PySequence_Contains(selfdata, item)) {
  			if (PyDict_DelItem(selfdata, item) == -1) {
  				Py_XDECREF(otherset);
--- 482,486 ----
  
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (PyDict_Contains(selfdata, item)) {
  			if (PyDict_DelItem(selfdata, item) == -1) {
  				Py_XDECREF(otherset);
***************
*** 542,546 ****
  	}
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (!PySequence_Contains(selfdata, item)) {
  			if (PyDict_SetItem(tgtdata, item, Py_True) == -1) {
  				Py_DECREF(it);
--- 542,546 ----
  	}
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (!PyDict_Contains(selfdata, item)) {
  			if (PyDict_SetItem(tgtdata, item, Py_True) == -1) {
  				Py_DECREF(it);
***************
*** 563,567 ****
  	}
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (!PySequence_Contains(otherdata, item)) {
  			if (PyDict_SetItem(tgtdata, item, Py_True) == -1) {
  				Py_DECREF(it);
--- 563,567 ----
  	}
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (!PyDict_Contains(otherdata, item)) {
  			if (PyDict_SetItem(tgtdata, item, Py_True) == -1) {
  				Py_DECREF(it);
***************
*** 635,639 ****
  	otherdata = ((PySetObject *)other)->data;
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (!PySequence_Contains(otherdata, item)) {
  			Py_DECREF(it);
  			Py_DECREF(item);
--- 635,639 ----
  	otherdata = ((PySetObject *)other)->data;
  	while ((item = PyIter_Next(it)) != NULL) {
! 		if (!PyDict_Contains(otherdata, item)) {
  			Py_DECREF(it);
  			Py_DECREF(item);





More information about the Python-checkins mailing list