]> granicus.if.org Git - python/commitdiff
Fix do_strip(): don't call PyUnicode_READ() in Py_UNICODE_ISSPACE() to not call
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 9 Apr 2013 20:21:08 +0000 (22:21 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 9 Apr 2013 20:21:08 +0000 (22:21 +0200)
it twice

Objects/unicodeobject.c

index ba72dba3bed59e0addc49680d23837a0a41dbcb9..52fe3bc55c7dde99b2b25b327da522d1bcc1b601 100644 (file)
@@ -11727,16 +11727,23 @@ do_strip(PyObject *self, int striptype)
 
     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++;
     }