summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-04-09 20:21:08 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-04-09 20:21:08 (GMT)
commit9c79e41fc5f5cb76b89af040b1675896d57051d9 (patch)
tree034b7847b55fe09b331426f1fc8774280182edfb /Objects/unicodeobject.c
parentb3a601450416be068933e237506767e6b150a4a1 (diff)
downloadcpython-9c79e41fc5f5cb76b89af040b1675896d57051d9.zip
cpython-9c79e41fc5f5cb76b89af040b1675896d57051d9.tar.gz
cpython-9c79e41fc5f5cb76b89af040b1675896d57051d9.tar.bz2
Fix do_strip(): don't call PyUnicode_READ() in Py_UNICODE_ISSPACE() to not call
it twice
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index ba72dba..52fe3bc 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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++;
}