From bd9adab13801dcd4826488ac9afbd03c4b3f0ccf Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 5 Sep 2002 20:18:08 +0000 Subject: Micro-optimization for list_contains. Factored double if test out of the loop. --- Objects/tupleobject.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 4c52de3..a6b862f 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -263,14 +263,13 @@ tuplecontains(PyTupleObject *a, PyObject *el) { 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), - Py_EQ); - if (cmp > 0) - return 1; - else if (cmp < 0) - return -1; - } + Py_EQ); + if (cmp > 0) + return 1; + if (cmp < 0) + return -1; return 0; } -- cgit v0.12