[Python-checkins] cpython: Fix do_strip(): don't call PyUnicode_READ() in Py_UNICODE_ISSPACE() to not call

victor.stinner python-checkins at python.org
Tue Apr 9 22:29:27 CEST 2013


http://hg.python.org/cpython/rev/dff6d02a51b6
changeset:   83221:dff6d02a51b6
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Apr 09 22:21:08 2013 +0200
summary:
  Fix do_strip(): don't call PyUnicode_READ() in Py_UNICODE_ISSPACE() to not call
it twice

files:
  Objects/unicodeobject.c |  13 ++++++++++---
  1 files changed, 10 insertions(+), 3 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -11727,16 +11727,23 @@
 
     i = 0;
     if (striptype != RIGHTSTRIP) {
-        while (i < len && Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, i))) {
+        while (i < len) {
+            Py_UCS4 ch = PyUnicode_READ(kind, data, i);
+            if (!Py_UNICODE_ISSPACE(ch))
+                break;
             i++;
         }
     }
 
     j = len;
     if (striptype != LEFTSTRIP) {
-        do {
+        j--;
+        while (j >= i) {
+            Py_UCS4 ch = PyUnicode_READ(kind, data, j);
+            if (!Py_UNICODE_ISSPACE(ch))
+                break;
             j--;
-        } while (j >= i && Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, j)));
+        }
         j++;
     }
 

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


More information about the Python-checkins mailing list