diff options
author | Raymond Hettinger <python@rcn.com> | 2005-09-24 21:23:05 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2005-09-24 21:23:05 (GMT) |
commit | 6b27cda64386195cd07dfb686e9486f1c4bc3159 (patch) | |
tree | 277a5c96e9683c63b573b508f8c4bd2d1374aed8 /Objects/listobject.c | |
parent | 9ceebd544516908e67c0f0d92c7a5f484e12beeb (diff) | |
download | cpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.zip cpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.tar.gz cpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.tar.bz2 |
Convert iterator __len__() methods to a private API.
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 3b7358a..1a96361 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -775,7 +775,7 @@ listextend(PyListObject *self, PyObject *b) iternext = *it->ob_type->tp_iternext; /* Guess a result list size. */ - n = PyObject_Size(b); + n = _PyObject_LengthCue(b); if (n < 0) { if (!PyErr_ExceptionMatches(PyExc_TypeError) && !PyErr_ExceptionMatches(PyExc_AttributeError)) { @@ -2764,21 +2764,23 @@ listiter_next(listiterobject *it) return NULL; } -static int +static PyObject * listiter_len(listiterobject *it) { int len; if (it->it_seq) { len = PyList_GET_SIZE(it->it_seq) - it->it_index; if (len >= 0) - return len; + return PyInt_FromLong((long)len); } - return 0; + return PyInt_FromLong(0); } -static PySequenceMethods listiter_as_sequence = { - (inquiry)listiter_len, /* sq_length */ - 0, /* sq_concat */ +PyDoc_STRVAR(length_cue_doc, "Private method returning an estimate of len(list(it))."); + +static PyMethodDef listiter_methods[] = { + {"_length_cue", (PyCFunction)listiter_len, METH_NOARGS, length_cue_doc}, + {NULL, NULL} /* sentinel */ }; PyTypeObject PyListIter_Type = { @@ -2795,7 +2797,7 @@ PyTypeObject PyListIter_Type = { 0, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ - &listiter_as_sequence, /* tp_as_sequence */ + 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ @@ -2811,13 +2813,8 @@ PyTypeObject PyListIter_Type = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)listiter_next, /* tp_iternext */ - 0, /* tp_methods */ + listiter_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ }; /*********************** List Reverse Iterator **************************/ |