mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
add list_contains and tuplecontains: efficient implementations of tp_contains
This commit is contained in:
parent
035a07e263
commit
37b1a26c89
2 changed files with 39 additions and 0 deletions
|
@ -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 = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue