[Python-checkins] python/dist/src/Objects iterobject.c,1.8,1.9
loewis@sourceforge.net
loewis@sourceforge.net
Wed, 08 May 2002 01:44:23 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv2607/Objects
Modified Files:
iterobject.c
Log Message:
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.
Index: iterobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/iterobject.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** iterobject.c 18 Mar 2002 20:43:51 -0000 1.8
--- iterobject.c 8 May 2002 08:44:21 -0000 1.9
***************
*** 13,16 ****
--- 13,21 ----
{
seqiterobject *it;
+
+ if (!PySequence_Check(seq)) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
it = PyObject_GC_New(seqiterobject, &PySeqIter_Type);
if (it == NULL)
***************
*** 64,68 ****
seq = it->it_seq;
! if (PyList_Check(seq)) {
PyObject *item;
if (it->it_index >= PyList_GET_SIZE(seq)) {
--- 69,73 ----
seq = it->it_seq;
! if (PyList_CheckExact(seq)) {
PyObject *item;
if (it->it_index >= PyList_GET_SIZE(seq)) {
***************
*** 74,79 ****
return item;
}
else {
! PyObject *result = PySequence_GetItem(seq, it->it_index++);
if (result != NULL) {
return result;
--- 79,95 ----
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_ITEM(seq, it->it_index);
! it->it_index++;
if (result != NULL) {
return result;