From 9c79e41fc5f5cb76b89af040b1675896d57051d9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 9 Apr 2013 22:21:08 +0200 Subject: [PATCH] Fix do_strip(): don't call PyUnicode_READ() in Py_UNICODE_ISSPACE() to not call it twice --- Objects/unicodeobject.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index ba72dba3bed..52fe3bc55c7 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++; }