summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-08 04:00:12 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-08 04:00:12 (GMT)
commit16a77adfbd745c202878fabb0b921514fec7ca16 (patch)
tree988fb5ffb34db1c7a12aa89c100efe1af17e80c6 /Include
parent2d84f2c95a59b815ef6864805bb6b04b79d0e106 (diff)
downloadcpython-16a77adfbd745c202878fabb0b921514fec7ca16.zip
cpython-16a77adfbd745c202878fabb0b921514fec7ca16.tar.gz
cpython-16a77adfbd745c202878fabb0b921514fec7ca16.tar.bz2
Generalize operator.indexOf (PySequence_Index) to work with any
iterable object. I'm not sure how that got overlooked before! Got rid of the internal _PySequence_IterContains, introduced a new internal _PySequence_IterSearch, and rewrote all the iteration-based "count of", "index of", and "is the object in it or not?" routines to just call the new function. I suppose it's slower this way, but the code duplication was getting depressing.
Diffstat (limited to 'Include')
-rw-r--r--Include/abstract.h26
1 files changed, 18 insertions, 8 deletions
diff --git a/Include/abstract.h b/Include/abstract.h
index f4c1b3e..d736efc 100644
--- a/Include/abstract.h
+++ b/Include/abstract.h
@@ -988,14 +988,24 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
DL_IMPORT(int) PySequence_Contains(PyObject *seq, PyObject *ob);
/*
Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
- Use __contains__ if possible, else _PySequence_IterContains().
- */
-
- DL_IMPORT(int) _PySequence_IterContains(PyObject *seq, PyObject *ob);
- /*
- Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
- Always uses the iteration protocol, and only Py_EQ comparisons.
- */
+ Use __contains__ if possible, else _PySequence_IterSearch().
+ */
+
+#define PY_ITERSEARCH_COUNT 1
+#define PY_ITERSEARCH_INDEX 2
+#define PY_ITERSEARCH_CONTAINS 3
+ DL_IMPORT(int) _PySequence_IterSearch(PyObject *seq, PyObject *obj,
+ int operation);
+ /*
+ Iterate over seq. Result depends on the operation:
+ PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
+ error.
+ PY_ITERSEARCH_INDEX: return 0-based index of first occurence of
+ obj in seq; set ValueError and return -1 if none found;
+ also return -1 on error.
+ PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on
+ error.
+ */
/* For DLL-level backwards compatibility */
#undef PySequence_In