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/dictobject.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/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index e90aca4..42e55e8 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2054,17 +2054,20 @@ dictiter_dealloc(dictiterobject *di) PyObject_Del(di); } -static int +static PyObject * dictiter_len(dictiterobject *di) { + int len = 0; if (di->di_dict != NULL && di->di_used == di->di_dict->ma_used) - return di->len; - return 0; + len = di->len; + return PyInt_FromLong(len); } -static PySequenceMethods dictiter_as_sequence = { - (inquiry)dictiter_len, /* sq_length */ - 0, /* sq_concat */ +PyDoc_STRVAR(length_cue_doc, "Private method returning an estimate of len(list(it))."); + +static PyMethodDef dictiter_methods[] = { + {"_length_cue", (PyCFunction)dictiter_len, METH_NOARGS, length_cue_doc}, + {NULL, NULL} /* sentinel */ }; static PyObject *dictiter_iternextkey(dictiterobject *di) @@ -2120,7 +2123,7 @@ PyTypeObject PyDictIterKey_Type = { 0, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ - &dictiter_as_sequence, /* tp_as_sequence */ + 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ @@ -2136,6 +2139,8 @@ PyTypeObject PyDictIterKey_Type = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)dictiter_iternextkey, /* tp_iternext */ + dictiter_methods, /* tp_methods */ + 0, }; static PyObject *dictiter_iternextvalue(dictiterobject *di) @@ -2191,7 +2196,7 @@ PyTypeObject PyDictIterValue_Type = { 0, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ - &dictiter_as_sequence, /* tp_as_sequence */ + 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ @@ -2207,6 +2212,8 @@ PyTypeObject PyDictIterValue_Type = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)dictiter_iternextvalue, /* tp_iternext */ + dictiter_methods, /* tp_methods */ + 0, }; static PyObject *dictiter_iternextitem(dictiterobject *di) @@ -2276,7 +2283,7 @@ PyTypeObject PyDictIterItem_Type = { 0, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ - &dictiter_as_sequence, /* tp_as_sequence */ + 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ @@ -2292,4 +2299,6 @@ PyTypeObject PyDictIterItem_Type = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)dictiter_iternextitem, /* tp_iternext */ + dictiter_methods, /* tp_methods */ + 0, }; |