diff options
author | Raymond Hettinger <python@rcn.com> | 2004-03-18 22:43:10 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-03-18 22:43:10 (GMT) |
commit | 435bf58b7bc9df7dd8683c3fc72b5b7ca1316541 (patch) | |
tree | 97f781846e1bf121dc94ca8f18282e5a3d6af8b9 /Objects/listobject.c | |
parent | 1e5809ff02201291df47d94dad843ca32048e4d3 (diff) | |
download | cpython-435bf58b7bc9df7dd8683c3fc72b5b7ca1316541.zip cpython-435bf58b7bc9df7dd8683c3fc72b5b7ca1316541.tar.gz cpython-435bf58b7bc9df7dd8683c3fc72b5b7ca1316541.tar.bz2 |
Make iterators length transparent where possible.
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 3bda245..f34ca70 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2707,6 +2707,19 @@ listiter_next(listiterobject *it) return NULL; } +static int +listiter_len(listiterobject *it) +{ + if (it->it_seq) + return PyList_GET_SIZE(it->it_seq) - it->it_index; + return 0; +} + +static PySequenceMethods listiter_as_sequence = { + (inquiry)listiter_len, /* sq_length */ + 0, /* sq_concat */ +}; + PyTypeObject PyListIter_Type = { PyObject_HEAD_INIT(&PyType_Type) 0, /* ob_size */ @@ -2721,7 +2734,7 @@ PyTypeObject PyListIter_Type = { 0, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ - 0, /* tp_as_sequence */ + &listiter_as_sequence, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ |