[Python-checkins] CVS: python/dist/src/Objects listobject.c,2.67,2.68 tupleobject.c,2.31,2.32
Jeremy Hylton
python-dev@python.org
2000年4月27日 17:41:06 -0400
Update of /projects/cvsroot/python/dist/src/Objects
In directory goon.cnri.reston.va.us:/home/jhylton/python/src/Objects
Modified Files:
listobject.c tupleobject.c
Log Message:
add list_contains and tuplecontains: efficient implementations of tp_contains
Index: listobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/listobject.c,v
retrieving revision 2.67
retrieving revision 2.68
diff -C2 -r2.67 -r2.68
*** listobject.c 2000年03月13日 16:01:29 2.67
--- listobject.c 2000年04月27日 21:41:03 2.68
***************
*** 307,310 ****
--- 307,330 ----
}
+
+
+ static int
+ list_contains(a, el)
+ PyListObject *a;
+ PyObject *el;
+ {
+ int i, cmp;
+
+ for (i = 0; i < a->ob_size; ++i) {
+ cmp = PyObject_Compare(el, PyList_GET_ITEM(a, i));
+ if (cmp == 0)
+ return 1;
+ if (PyErr_Occurred())
+ return -1;
+ }
+ return 0;
+ }
+
+
static PyObject *
list_item(a, i)
***************
*** 1448,1451 ****
--- 1468,1472 ----
(intobjargproc)list_ass_item, /*sq_ass_item*/
(intintobjargproc)list_ass_slice, /*sq_ass_slice*/
+ (objobjproc)list_contains, /*sq_contains*/
};
Index: tupleobject.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Objects/tupleobject.c,v
retrieving revision 2.31
retrieving revision 2.32
diff -C2 -r2.31 -r2.32
*** tupleobject.c 2000年04月21日 21:15:05 2.31
--- tupleobject.c 2000年04月27日 21:41:03 2.32
***************
*** 282,285 ****
--- 282,302 ----
}
+ static int
+ tuplecontains(a, el)
+ PyTupleObject *a;
+ PyObject *el;
+ {
+ int i, cmp;
+
+ for (i = 0; i < a->ob_size; ++i) {
+ cmp = PyObject_Compare(el, PyTuple_GET_ITEM(a, i));
+ if (cmp == 0)
+ return 1;
+ if (PyErr_Occurred())
+ return -1;
+ }
+ return 0;
+ }
+
static PyObject *
tupleitem(a, i)
***************
*** 410,413 ****
--- 427,431 ----
0, /*sq_ass_item*/
0, /*sq_ass_slice*/
+ (objobjproc)tuplecontains, /*sq_contains*/
};