[Python-checkins] cpython: Simplify _count_elements() in _collections

victor.stinner python-checkins at python.org
Wed Apr 20 23:25:39 CEST 2011


http://hg.python.org/cpython/rev/4bd68b1f8702
changeset:   69504:4bd68b1f8702
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Wed Apr 20 23:23:52 2011 +0200
summary:
  Simplify _count_elements() in _collections

PyIter_Next() cannot return a PyExc_StopIteration: it clears this exception.

files:
  Modules/_collectionsmodule.c |  16 ++++------------
  1 files changed, 4 insertions(+), 12 deletions(-)


diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1552,12 +1552,8 @@
     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 @@
     } 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))

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list