[Python-checkins] cpython: _copy_characters() fails more quickly in debug mode on inconsistent state

victor.stinner python-checkins at python.org
Thu Oct 6 02:47:07 CEST 2011


http://hg.python.org/cpython/rev/357750802e86
changeset:   72719:357750802e86
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Thu Oct 06 02:47:11 2011 +0200
summary:
  _copy_characters() fails more quickly in debug mode on inconsistent state

files:
  Objects/unicodeobject.c |  28 ++++++++++++++++++++--------
  1 files changed, 20 insertions(+), 8 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1052,20 +1052,32 @@
             Py_UCS4 ch;
             Py_ssize_t i;
 
+#ifdef Py_DEBUG
             for (i=0; i < how_many; i++) {
                 ch = PyUnicode_READ(from_kind, from_data, from_start + i);
-                if (check_maxchar) {
+                assert(ch <= to_maxchar);
+                PyUnicode_WRITE(to_kind, to_data, to_start + i, ch);
+            }
+#else
+            if (!check_maxchar) {
+                for (i=0; i < how_many; i++) {
+                    ch = PyUnicode_READ(from_kind, from_data, from_start + i);
+                    PyUnicode_WRITE(to_kind, to_data, to_start + i, ch);
+                }
+            }
+            else {
+                for (i=0; i < how_many; i++) {
+                    ch = PyUnicode_READ(from_kind, from_data, from_start + i);
                     if (ch > to_maxchar)
                         return 1;
-                }
-                else {
-                    assert(ch <= to_maxchar);
-                }
-                PyUnicode_WRITE(to_kind, to_data, to_start + i, ch);
-            }
+                    PyUnicode_WRITE(to_kind, to_data, to_start + i, ch);
+                }
+            }
+#endif
         }
         else {
-            return -1;
+            assert(0 && "inconsistent state");
+            return 1;
         }
     }
     return 0;

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


More information about the Python-checkins mailing list