diff options
| author | Victor Stinner <victor.stinner@gmail.com> | 2013-04-09 22:21:08 +0200 |
|---|---|---|
| committer | Victor Stinner <victor.stinner@gmail.com> | 2013-04-09 22:21:08 +0200 |
| commit | 9c79e41fc5f5cb76b89af040b1675896d57051d9 (patch) | |
| tree | 034b7847b55fe09b331426f1fc8774280182edfb /Objects | |
| parent | b3a601450416be068933e237506767e6b150a4a1 (diff) | |
| download | cpython-git-9c79e41fc5f5cb76b89af040b1675896d57051d9.tar.gz | |
Fix do_strip(): don't call PyUnicode_READ() in Py_UNICODE_ISSPACE() to not call
it twice
Diffstat (limited to 'Objects')
| -rw-r--r-- | Objects/unicodeobject.c | 13 |
1 files changed, 10 insertions, 3 deletions
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++; } |
