summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2002-05-08 08:44:21 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2002-05-08 08:44:21 (GMT)
commit01f94bda38b8f9956cfa1b227f2ebdb8ea2dfdd7 (patch)
tree07d60d276dc54212ddf73496f865f00c6821417c /Objects
parent000e37c3c433f42bafc68eee78633da147734808 (diff)
downloadcpython-01f94bda38b8f9956cfa1b227f2ebdb8ea2dfdd7.zip
cpython-01f94bda38b8f9956cfa1b227f2ebdb8ea2dfdd7.tar.gz
cpython-01f94bda38b8f9956cfa1b227f2ebdb8ea2dfdd7.tar.bz2
Patch #552433: Special-case tuples. Avoid sub-type checking for lists.
Avoid checks for negative indices and duplicate checks for support of the sequence protocol.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/iterobject.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/Objects/iterobject.c b/Objects/iterobject.c
index 789eb6c..de9f2f9 100644
--- a/Objects/iterobject.c
+++ b/Objects/iterobject.c
@@ -12,6 +12,11 @@ PyObject *
PySeqIter_New(PyObject *seq)
{
seqiterobject *it;
+
+ if (!PySequence_Check(seq)) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
it = PyObject_GC_New(seqiterobject, &PySeqIter_Type);
if (it == NULL)
return NULL;
@@ -63,7 +68,7 @@ iter_iternext(PyObject *iterator)
it = (seqiterobject *)iterator;
seq = it->it_seq;
- if (PyList_Check(seq)) {
+ if (PyList_CheckExact(seq)) {
PyObject *item;
if (it->it_index >= PyList_GET_SIZE(seq)) {
return NULL;
@@ -73,8 +78,19 @@ iter_iternext(PyObject *iterator)
Py_INCREF(item);
return item;
}
+ if (PyTuple_CheckExact(seq)) {
+ PyObject *item;
+ if (it->it_index >= PyTuple_GET_SIZE(seq)) {
+ return NULL;
+ }
+ item = PyTuple_GET_ITEM(seq, it->it_index);
+ it->it_index++;
+ Py_INCREF(item);
+ return item;
+ }
else {
- PyObject *result = PySequence_GetItem(seq, it->it_index++);
+ PyObject *result = PySequence_ITEM(seq, it->it_index);
+ it->it_index++;
if (result != NULL) {
return result;
}