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
6980be40
Commit
6980be40
authored
Nov 06, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #25558: Refactoring OrderedDict iteration.
parents
e2e0deec
9c967611
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
40 deletions
+31
-40
Objects/odictobject.c
Objects/odictobject.c
+31
-40
No files found.
Objects/odictobject.c
View file @
6980be40
...
...
@@ -1829,7 +1829,7 @@ done:
static
PyObject
*
odictiter_iternext
(
odictiterobject
*
di
)
{
PyObject
*
value
;
PyObject
*
result
,
*
value
;
PyObject
*
key
=
odictiter_nextkey
(
di
);
/* new reference */
if
(
key
==
NULL
)
...
...
@@ -1840,53 +1840,44 @@ odictiter_iternext(odictiterobject *di)
return
key
;
}
/* Handle the items case. */
if
(
di
->
kind
&
_odict_ITER_KEYS
)
{
PyObject
*
result
=
di
->
di_result
;
value
=
PyODict_GetItem
((
PyObject
*
)
di
->
di_odict
,
key
);
/* borrowed */
if
(
value
==
NULL
)
{
if
(
!
PyErr_Occurred
())
PyErr_SetObject
(
PyExc_KeyError
,
key
);
Py_DECREF
(
key
);
goto
done
;
}
Py_INCREF
(
value
);
if
(
result
->
ob_refcnt
==
1
)
{
/* not in use so we can reuse it
* (the common case during iteration) */
Py_INCREF
(
result
);
Py_DECREF
(
PyTuple_GET_ITEM
(
result
,
0
));
/* borrowed */
Py_DECREF
(
PyTuple_GET_ITEM
(
result
,
1
));
/* borrowed */
}
else
{
result
=
PyTuple_New
(
2
);
if
(
result
==
NULL
)
{
Py_DECREF
(
key
);
Py_DECREF
(
value
);
goto
done
;
}
}
value
=
PyODict_GetItem
((
PyObject
*
)
di
->
di_odict
,
key
);
/* borrowed */
if
(
value
==
NULL
)
{
if
(
!
PyErr_Occurred
())
PyErr_SetObject
(
PyExc_KeyError
,
key
);
Py_DECREF
(
key
);
goto
done
;
}
Py_INCREF
(
value
);
PyTuple_SET_ITEM
(
result
,
0
,
key
);
/* steals reference */
PyTuple_SET_ITEM
(
result
,
1
,
value
);
/* steals reference */
/* Handle the values case. */
if
(
!
(
di
->
kind
&
_odict_ITER_KEYS
))
{
Py_DECREF
(
key
);
return
value
;
}
return
result
;
/* Handle the items case. */
result
=
di
->
di_result
;
if
(
Py_REFCNT
(
result
)
==
1
)
{
/* not in use so we can reuse it
* (the common case during iteration) */
Py_INCREF
(
result
);
Py_DECREF
(
PyTuple_GET_ITEM
(
result
,
0
));
/* borrowed */
Py_DECREF
(
PyTuple_GET_ITEM
(
result
,
1
));
/* borrowed */
}
/* Handle the values case. */
else
{
value
=
PyODict_GetItem
((
PyObject
*
)
di
->
di_odict
,
key
);
Py_DECREF
(
key
);
if
(
value
==
NULL
)
{
if
(
!
PyErr_Occurred
())
PyErr_SetObject
(
PyExc_KeyError
,
key
);
result
=
PyTuple_New
(
2
);
if
(
result
==
NULL
)
{
Py_DECREF
(
key
);
Py_DECREF
(
value
);
goto
done
;
}
Py_INCREF
(
value
);
return
value
;
}
PyTuple_SET_ITEM
(
result
,
0
,
key
);
/* steals reference */
PyTuple_SET_ITEM
(
result
,
1
,
value
);
/* steals reference */
return
result
;
done:
Py_CLEAR
(
di
->
di_current
);
Py_CLEAR
(
di
->
di_odict
);
...
...
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