From: Victor Stinner Date: Wed, 20 Apr 2011 21:23:52 +0000 (+0200) Subject: Simplify _count_elements() in _collections X-Git-Tag: v3.3.0a1~2533 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a154b5cea43996f69e800e59a8aa0e75095db7f4;p=python Simplify _count_elements() in _collections PyIter_Next() cannot return a PyExc_StopIteration: it clears this exception. --- diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 5545d1eff2..8743408d8c 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -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))