]> granicus.if.org Git - python/commitdiff
Simplify _count_elements() in _collections
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 20 Apr 2011 21:23:52 +0000 (23:23 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 20 Apr 2011 21:23:52 +0000 (23:23 +0200)
PyIter_Next() cannot return a PyExc_StopIteration: it clears this exception.

Modules/_collectionsmodule.c

index 5545d1eff2898b62127797dfd0e978bb1c44c81d..8743408d8c2aab4901027eecbcf92b83fb1c91a8 100644 (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))