cpython: ad44d551c13c (original) (raw)
Mercurial > cpython
changeset 98981:ad44d551c13c 3.5
Issue #25558: Refactoring OrderedDict iteration. [#25558]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Fri, 06 Nov 2015 10:39:51 +0200 |
parents | 8702efa1feb4 |
children | 51f3547da99c 1594c23d8c2f |
files | Objects/odictobject.c |
diffstat | 1 files changed, 33 insertions(+), 42 deletions(-)[+] [-] Objects/odictobject.c 75 |
line wrap: on
line diff
--- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1829,7 +1829,7 @@ done: static PyObject * odictiter_iternext(odictiterobject *di) {
- PyObject *result, *value; PyObject key = odictiter_nextkey(di); / new reference */ if (key == NULL) @@ -1840,52 +1840,43 @@ odictiter_iternext(odictiterobject *di) return key; }
- /* Handle the items case. */
- if (di->kind & _odict_ITER_KEYS) {
PyObject *result = di->di_result;[](#l1.18)
- value = PyODict_GetItem((PyObject )di->di_odict, key); / borrowed */
- if (value == NULL) {
if (!PyErr_Occurred())[](#l1.21)
PyErr_SetObject(PyExc_KeyError, key);[](#l1.22)
Py_DECREF(key);[](#l1.23)
goto done;[](#l1.24)
- }
- Py_INCREF(value);
- /* Handle the values case. */
- if (!(di->kind & _odict_ITER_KEYS)) {
Py_DECREF(key);[](#l1.30)
return value;[](#l1.31)
- }
value = PyODict_GetItem((PyObject *)di->di_odict, key); /* borrowed */[](#l1.34)
if (value == NULL) {[](#l1.35)
if (!PyErr_Occurred())[](#l1.36)
PyErr_SetObject(PyExc_KeyError, key);[](#l1.37)
- if (Py_REFCNT(result) == 1) {
/* not in use so we can reuse it[](#l1.42)
* (the common case during iteration) */[](#l1.43)
Py_INCREF(result);[](#l1.44)
Py_DECREF(PyTuple_GET_ITEM(result, 0)); /* borrowed */[](#l1.45)
Py_DECREF(PyTuple_GET_ITEM(result, 1)); /* borrowed */[](#l1.46)
- }
- else {
result = PyTuple_New(2);[](#l1.49)
if (result == NULL) {[](#l1.50) Py_DECREF(key);[](#l1.51)
Py_DECREF(value);[](#l1.52) goto done;[](#l1.53) }[](#l1.54)
Py_INCREF(value);[](#l1.55)
if (result->ob_refcnt == 1) {[](#l1.57)
/* not in use so we can reuse it[](#l1.58)
* (the common case during iteration) */[](#l1.59)
Py_INCREF(result);[](#l1.60)
Py_DECREF(PyTuple_GET_ITEM(result, 0)); /* borrowed */[](#l1.61)
Py_DECREF(PyTuple_GET_ITEM(result, 1)); /* borrowed */[](#l1.62)
}[](#l1.63)
else {[](#l1.64)
result = PyTuple_New(2);[](#l1.65)
if (result == NULL) {[](#l1.66)
Py_DECREF(key);[](#l1.67)
Py_DECREF(value);[](#l1.68)
goto done;[](#l1.69)
}[](#l1.70)
}[](#l1.71)
PyTuple_SET_ITEM(result, 0, key); /* steals reference */[](#l1.74)
PyTuple_SET_ITEM(result, 1, value); /* steals reference */[](#l1.75)
return result;[](#l1.77)
- }
- /* Handle the values case. */
- else {
value = PyODict_GetItem((PyObject *)di->di_odict, key);[](#l1.81)
Py_DECREF(key);[](#l1.82)
if (value == NULL) {[](#l1.83)
if (!PyErr_Occurred())[](#l1.84)
PyErr_SetObject(PyExc_KeyError, key);[](#l1.85)
goto done;[](#l1.86)
}[](#l1.87)
Py_INCREF(value);[](#l1.88)
return value;[](#l1.89)
- }