Commit aae5999b authored by Raymond Hettinger's avatar Raymond Hettinger

Micro-optimization for list_contains. Factored double if test

out of the loop.
parent 63857a45
...@@ -320,16 +320,15 @@ list_length(PyListObject *a) ...@@ -320,16 +320,15 @@ list_length(PyListObject *a)
static int static int
list_contains(PyListObject *a, PyObject *el) list_contains(PyListObject *a, PyObject *el)
{ {
int i; int i, cmp;
for (i = 0; i < a->ob_size; ++i) { for (i = 0, cmp = 0 ; cmp == 0 && i < a->ob_size; ++i)
int cmp = PyObject_RichCompareBool(el, PyList_GET_ITEM(a, i), cmp = PyObject_RichCompareBool(el, PyList_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