projects
/
python
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
aae5999
)
Micro-optimization for list_contains. Factored double if test
author
Raymond Hettinger
<python@rcn.com>
Thu, 5 Sep 2002 20:18:08 +0000
(20:18 +0000)
committer
Raymond Hettinger
<python@rcn.com>
Thu, 5 Sep 2002 20:18:08 +0000
(20:18 +0000)
out of the loop.
Objects/tupleobject.c
patch
|
blob
|
history
diff --git
a/Objects/tupleobject.c
b/Objects/tupleobject.c
index 4c52de3aa4dd97c9551b3a75b47056459c57dcbb..a6b862f442630c8ebcaea15f6e181e023918396b 100644
(file)
--- 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;
}