summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-11-08 11:58:44 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-11-08 11:58:44 (GMT)
commit001f228f369d5c3e9fc28ae7a9815e1317bbe72f (patch)
treee52b8b738e2b2e498b988ba7bb73a03f57e78a91
parente21f6066574cfecbf0f5783ae924309a1afba0b0 (diff)
downloadcpython-001f228f369d5c3e9fc28ae7a9815e1317bbe72f.zip
cpython-001f228f369d5c3e9fc28ae7a9815e1317bbe72f.tar.gz
cpython-001f228f369d5c3e9fc28ae7a9815e1317bbe72f.tar.bz2
Improve the reverse list iterator to free memory as soon as the iterator
is exhausted.
-rw-r--r--Objects/listobject.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 7198e34..3782c3b 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2771,7 +2771,7 @@ PyTypeObject PyListIter_Type = {
typedef struct {
PyObject_HEAD
long it_index;
- PyListObject *it_seq;
+ PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
} listreviterobject;
PyTypeObject PyListRevIter_Type;
@@ -2819,6 +2819,9 @@ listreviter_next(listreviterobject *it)
item = PyList_GET_ITEM(it->it_seq, it->it_index);
it->it_index--;
Py_INCREF(item);
+ } else if (it->it_seq != NULL) {
+ Py_DECREF(it->it_seq);
+ it->it_seq = NULL;
}
return item;
}