summaryrefslogtreecommitdiffstats
path: root/Objects/tupleobject.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-04-27 21:41:03 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-04-27 21:41:03 (GMT)
commit37b1a26c89d5f2583f04ac4efb3d799ff07634f6 (patch)
tree390a145cc3f5c6d11be350967ddf8254367be1b0 /Objects/tupleobject.c
parent035a07e263edd2ebb24c07862d9de6488d8bb203 (diff)
downloadcpython-37b1a26c89d5f2583f04ac4efb3d799ff07634f6.zip
cpython-37b1a26c89d5f2583f04ac4efb3d799ff07634f6.tar.gz
cpython-37b1a26c89d5f2583f04ac4efb3d799ff07634f6.tar.bz2
add list_contains and tuplecontains: efficient implementations of tp_contains
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r--Objects/tupleobject.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 98448bd..d1627a9 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -281,6 +281,23 @@ tuplelength(a)
return a->ob_size;
}
+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)
register PyTupleObject *a;
@@ -409,6 +426,7 @@ static PySequenceMethods tuple_as_sequence = {
(intintargfunc)tupleslice, /*sq_slice*/
0, /*sq_ass_item*/
0, /*sq_ass_slice*/
+ (objobjproc)tuplecontains, /*sq_contains*/
};
PyTypeObject PyTuple_Type = {