From: Victor Stinner Date: Tue, 9 Apr 2013 20:21:08 +0000 (+0200) Subject: Fix do_strip(): don't call PyUnicode_READ() in Py_UNICODE_ISSPACE() to not call X-Git-Tag: v3.4.0a1~998^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c79e41fc5f5cb76b89af040b1675896d57051d9;p=python Fix do_strip(): don't call PyUnicode_READ() in Py_UNICODE_ISSPACE() to not call it twice --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index ba72dba3be..52fe3bc55c 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++; }