Commit e45fcd87 authored by Raymond Hettinger's avatar Raymond Hettinger

Micro-optimization for list_contains. Factored double if test

out of the loop.
parent 0aa581b8
...@@ -263,14 +263,13 @@ tuplecontains(PyTupleObject *a, PyObject *el) ...@@ -263,14 +263,13 @@ tuplecontains(PyTupleObject *a, PyObject *el)
{ {
int i, cmp; int i, cmp;
for (i = 0; i < a->ob_size; ++i) { for (i = 0, cmp = 0 ; cmp == 0 && i < a->ob_size; ++i)
cmp = PyObject_RichCompareBool(el, PyTuple_GET_ITEM(a, i), cmp = PyObject_RichCompareBool(el, PyTuple_GET_ITEM(a, i),
Py_EQ); Py_EQ);
if (cmp > 0) if (cmp > 0)
return 1; return 1;
else if (cmp < 0) if (cmp < 0)
return -1; return -1;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment