Simplify _count_elements() in _collections

PyIter_Next() cannot return a PyExc_StopIteration: it clears this exception.
This commit is contained in:
Victor Stinner 2011-04-20 23:23:52 +02:00
parent 52d8fb5c54
commit a154b5cea4
1 changed files with 4 additions and 12 deletions

View File

@ -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))