mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Fix do_strip(): don't call PyUnicode_READ() in Py_UNICODE_ISSPACE() to not call
it twice
This commit is contained in:
parent
b3a6014504
commit
9c79e41fc5
1 changed files with 10 additions and 3 deletions
|
@ -11727,16 +11727,23 @@ do_strip(PyObject *self, int striptype)
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (striptype != RIGHTSTRIP) {
|
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++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
j = len;
|
j = len;
|
||||||
if (striptype != LEFTSTRIP) {
|
if (striptype != LEFTSTRIP) {
|
||||||
do {
|
j--;
|
||||||
|
while (j >= i) {
|
||||||
|
Py_UCS4 ch = PyUnicode_READ(kind, data, j);
|
||||||
|
if (!Py_UNICODE_ISSPACE(ch))
|
||||||
|
break;
|
||||||
j--;
|
j--;
|
||||||
} while (j >= i && Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, j)));
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue