@@ -1829,7 +1829,7 @@ odictiter_nextkey(odictiterobject *di)
1829
1829
static PyObject *
1830
1830
odictiter_iternext (odictiterobject * di )
1831
1831
{
1832
- PyObject * value ;
1832
+ PyObject * result , * value ;
1833
1833
PyObject * key = odictiter_nextkey (di ); /* new reference */
1834
1834
1835
1835
if (key == NULL )
@@ -1840,53 +1840,44 @@ odictiter_iternext(odictiterobject *di)
1840
1840
return key ;
1841
1841
}
1842
1842
1843
- /* Handle the items case. */
1844
- if (di -> kind & _odict_ITER_KEYS ) {
1845
- PyObject * result = di -> di_result ;
1846
-
1847
- value = PyODict_GetItem ((PyObject * )di -> di_odict , key ); /* borrowed */
1848
- if (value == NULL ) {
1849
- if (!PyErr_Occurred ())
1850
- PyErr_SetObject (PyExc_KeyError , key );
1851
- Py_DECREF (key );
1852
- goto done ;
1853
- }
1854
- Py_INCREF (value );
1855
-
1856
- if (result -> ob_refcnt == 1 ) {
1857
- /* not in use so we can reuse it
1858
- * (the common case during iteration) */
1859
- Py_INCREF (result );
1860
- Py_DECREF (PyTuple_GET_ITEM (result , 0 )); /* borrowed */
1861
- Py_DECREF (PyTuple_GET_ITEM (result , 1 )); /* borrowed */
1862
- }
1863
- else {
1864
- result = PyTuple_New (2 );
1865
- if (result == NULL ) {
1866
- Py_DECREF (key );
1867
- Py_DECREF (value );
1868
- goto done ;
1869
- }
1870
- }
1843
+ value = PyODict_GetItem ((PyObject * )di -> di_odict , key ); /* borrowed */
1844
+ if (value == NULL ) {
1845
+ if (!PyErr_Occurred ())
1846
+ PyErr_SetObject (PyExc_KeyError , key );
1847
+ Py_DECREF (key );
1848
+ goto done ;
1849
+ }
1850
+ Py_INCREF (value );
1871
1851
1872
- PyTuple_SET_ITEM (result , 0 , key ); /* steals reference */
1873
- PyTuple_SET_ITEM (result , 1 , value ); /* steals reference */
1852
+ /* Handle the values case. */
1853
+ if (!(di -> kind & _odict_ITER_KEYS )) {
1854
+ Py_DECREF (key );
1855
+ return value ;
1856
+ }
1874
1857
1875
- return result ;
1858
+ /* Handle the items case. */
1859
+ result = di -> di_result ;
1860
+
1861
+ if (Py_REFCNT (result ) == 1 ) {
1862
+ /* not in use so we can reuse it
1863
+ * (the common case during iteration) */
1864
+ Py_INCREF (result );
1865
+ Py_DECREF (PyTuple_GET_ITEM (result , 0 )); /* borrowed */
1866
+ Py_DECREF (PyTuple_GET_ITEM (result , 1 )); /* borrowed */
1876
1867
}
1877
- /* Handle the values case. */
1878
1868
else {
1879
- value = PyODict_GetItem ((PyObject * )di -> di_odict , key );
1880
- Py_DECREF (key );
1881
- if (value == NULL ) {
1882
- if (!PyErr_Occurred ())
1883
- PyErr_SetObject (PyExc_KeyError , key );
1869
+ result = PyTuple_New (2 );
1870
+ if (result == NULL ) {
1871
+ Py_DECREF (key );
1872
+ Py_DECREF (value );
1884
1873
goto done ;
1885
1874
}
1886
- Py_INCREF (value );
1887
- return value ;
1888
1875
}
1889
1876
1877
+ PyTuple_SET_ITEM (result , 0 , key ); /* steals reference */
1878
+ PyTuple_SET_ITEM (result , 1 , value ); /* steals reference */
1879
+ return result ;
1880
+
1890
1881
done :
1891
1882
Py_CLEAR (di -> di_current );
1892
1883
Py_CLEAR (di -> di_odict );
0 commit comments