diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-06 00:47:11 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-06 00:47:11 (GMT) |
commit | 56c161ab00bc1fe3fbac6777576105770d024581 (patch) | |
tree | 1b4cab2df9a4bfd4f269f88e33fd19b752696451 /Objects/unicodeobject.c | |
parent | 46084bad8826e547b66496867a5ba0e21c0b4a45 (diff) | |
download | cpython-56c161ab00bc1fe3fbac6777576105770d024581.zip cpython-56c161ab00bc1fe3fbac6777576105770d024581.tar.gz cpython-56c161ab00bc1fe3fbac6777576105770d024581.tar.bz2 |
_copy_characters() fails more quickly in debug mode on inconsistent state
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 21cafb3..a64f795 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1052,20 +1052,32 @@ _copy_characters(PyObject *to, Py_ssize_t to_start, 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; + PyUnicode_WRITE(to_kind, to_data, to_start + i, ch); } - else { - assert(ch <= to_maxchar); - } - PyUnicode_WRITE(to_kind, to_data, to_start + i, ch); } +#endif } else { - return -1; + assert(0 && "inconsistent state"); + return 1; } } return 0; |