Commit 001f228f authored by Raymond Hettinger's avatar Raymond Hettinger

Improve the reverse list iterator to free memory as soon as the iterator

is exhausted.
parent e21f6066
...@@ -2771,7 +2771,7 @@ PyTypeObject PyListIter_Type = { ...@@ -2771,7 +2771,7 @@ PyTypeObject PyListIter_Type = {
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD
long it_index; long it_index;
PyListObject *it_seq; PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
} listreviterobject; } listreviterobject;
PyTypeObject PyListRevIter_Type; PyTypeObject PyListRevIter_Type;
...@@ -2819,6 +2819,9 @@ listreviter_next(listreviterobject *it) ...@@ -2819,6 +2819,9 @@ listreviter_next(listreviterobject *it)
item = PyList_GET_ITEM(it->it_seq, it->it_index); item = PyList_GET_ITEM(it->it_seq, it->it_index);
it->it_index--; it->it_index--;
Py_INCREF(item); Py_INCREF(item);
} else if (it->it_seq != NULL) {
Py_DECREF(it->it_seq);
it->it_seq = NULL;
} }
return item; return item;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment