diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-04-27 21:41:03 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-04-27 21:41:03 (GMT) |
commit | 37b1a26c89d5f2583f04ac4efb3d799ff07634f6 (patch) | |
tree | 390a145cc3f5c6d11be350967ddf8254367be1b0 /Objects/listobject.c | |
parent | 035a07e263edd2ebb24c07862d9de6488d8bb203 (diff) | |
download | cpython-37b1a26c89d5f2583f04ac4efb3d799ff07634f6.zip cpython-37b1a26c89d5f2583f04ac4efb3d799ff07634f6.tar.gz cpython-37b1a26c89d5f2583f04ac4efb3d799ff07634f6.tar.bz2 |
add list_contains and tuplecontains: efficient implementations of tp_contains
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 673028f..005d709 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -306,6 +306,26 @@ list_length(a) return a->ob_size; } + + +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) PyListObject *a; @@ -1447,6 +1467,7 @@ static PySequenceMethods list_as_sequence = { (intintargfunc)list_slice, /*sq_slice*/ (intobjargproc)list_ass_item, /*sq_ass_item*/ (intintobjargproc)list_ass_slice, /*sq_ass_slice*/ + (objobjproc)list_contains, /*sq_contains*/ }; PyTypeObject PyList_Type = { |