Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
435bf58b
Commit
435bf58b
authored
Mar 18, 2004
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make iterators length transparent where possible.
parent
1e5809ff
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
3 deletions
+42
-3
Objects/iterobject.c
Objects/iterobject.c
+14
-1
Objects/listobject.c
Objects/listobject.c
+14
-1
Objects/tupleobject.c
Objects/tupleobject.c
+14
-1
No files found.
Objects/iterobject.c
View file @
435bf58b
...
...
@@ -71,6 +71,19 @@ iter_iternext(PyObject *iterator)
return
NULL
;
}
static
int
iter_len
(
seqiterobject
*
it
)
{
if
(
it
->
it_seq
)
return
PyObject_Size
(
it
->
it_seq
)
-
it
->
it_index
;
return
0
;
}
static
PySequenceMethods
iter_as_sequence
=
{
(
inquiry
)
iter_len
,
/* sq_length */
0
,
/* sq_concat */
};
PyTypeObject
PySeqIter_Type
=
{
PyObject_HEAD_INIT
(
&
PyType_Type
)
0
,
/* ob_size */
...
...
@@ -85,7 +98,7 @@ PyTypeObject PySeqIter_Type = {
0
,
/* tp_compare */
0
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
&
iter_as_sequence
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
0
,
/* tp_hash */
0
,
/* tp_call */
...
...
Objects/listobject.c
View file @
435bf58b
...
...
@@ -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 */
...
...
Objects/tupleobject.c
View file @
435bf58b
...
...
@@ -839,6 +839,19 @@ tupleiter_next(tupleiterobject *it)
return
NULL
;
}
static
int
tupleiter_len
(
tupleiterobject
*
it
)
{
if
(
it
->
it_seq
)
return
PyTuple_GET_SIZE
(
it
->
it_seq
)
-
it
->
it_index
;
return
0
;
}
static
PySequenceMethods
tupleiter_as_sequence
=
{
(
inquiry
)
tupleiter_len
,
/* sq_length */
0
,
/* sq_concat */
};
PyTypeObject
PyTupleIter_Type
=
{
PyObject_HEAD_INIT
(
&
PyType_Type
)
0
,
/* ob_size */
...
...
@@ -853,7 +866,7 @@ PyTypeObject PyTupleIter_Type = {
0
,
/* tp_compare */
0
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
&
tupleiter_as_sequence
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
0
,
/* tp_hash */
0
,
/* tp_call */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment