Commit a154b5ce authored by Victor Stinner's avatar Victor Stinner

Simplify _count_elements() in _collections

PyIter_Next() cannot return a PyExc_StopIteration: it clears this exception.
parent 52d8fb5c
......@@ -1552,12 +1552,8 @@ _count_elements(PyObject *self, PyObject *args)
if (PyDict_CheckExact(mapping)) {
while (1) {
key = PyIter_Next(it);
if (key == NULL) {
if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration))
PyErr_Clear();
else
break;
}
if (key == NULL)
break;
oldval = PyDict_GetItem(mapping, key);
if (oldval == NULL) {
if (PyDict_SetItem(mapping, key, one) == -1)
......@@ -1575,12 +1571,8 @@ _count_elements(PyObject *self, PyObject *args)
} else {
while (1) {
key = PyIter_Next(it);
if (key == NULL) {
if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration))
PyErr_Clear();
else
break;
}
if (key == NULL)
break;
oldval = PyObject_GetItem(mapping, key);
if (oldval == NULL) {
if (!PyErr_Occurred() || !PyErr_ExceptionMatches(PyExc_KeyError))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment