summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-09-05 20:18:08 (GMT)
committerRaymond Hettinger <python@rcn.com>2002-09-05 20:18:08 (GMT)
commitbd9adab13801dcd4826488ac9afbd03c4b3f0ccf (patch)
tree1278151d9914677f2ce08229ee555a913c747941 /Objects
parentaae5999b44e54394f91e84b775d29230d3a0a2ef (diff)
downloadcpython-bd9adab13801dcd4826488ac9afbd03c4b3f0ccf.zip
cpython-bd9adab13801dcd4826488ac9afbd03c4b3f0ccf.tar.gz
cpython-bd9adab13801dcd4826488ac9afbd03c4b3f0ccf.tar.bz2
Micro-optimization for list_contains. Factored double if test
out of the loop.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/tupleobject.c13
1 files 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;
}