]> granicus.if.org Git - python/commitdiff
Micro-optimization for list_contains. Factored double if test
authorRaymond Hettinger <python@rcn.com>
Thu, 5 Sep 2002 20:18:08 +0000 (20:18 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 5 Sep 2002 20:18:08 +0000 (20:18 +0000)
out of the loop.

Objects/tupleobject.c

index 4c52de3aa4dd97c9551b3a75b47056459c57dcbb..a6b862f442630c8ebcaea15f6e181e023918396b 100644 (file)
@@ -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;
 }