mirror of https://github.com/python/cpython
Optimize unicode_subscript() for step != 1 and ascii strings
This commit is contained in:
parent
127226ba69
commit
55c991197b
|
@ -12614,18 +12614,22 @@ unicode_subscript(PyUnicodeObject* self, PyObject* item)
|
||||||
start, start + slicelength);
|
start, start + slicelength);
|
||||||
}
|
}
|
||||||
/* General case */
|
/* General case */
|
||||||
max_char = 0;
|
|
||||||
src_kind = PyUnicode_KIND(self);
|
src_kind = PyUnicode_KIND(self);
|
||||||
kind_limit = kind_maxchar_limit(src_kind);
|
|
||||||
src_data = PyUnicode_DATA(self);
|
src_data = PyUnicode_DATA(self);
|
||||||
for (cur = start, i = 0; i < slicelength; cur += step, i++) {
|
if (!PyUnicode_IS_ASCII(self)) {
|
||||||
ch = PyUnicode_READ(src_kind, src_data, cur);
|
kind_limit = kind_maxchar_limit(src_kind);
|
||||||
if (ch > max_char) {
|
max_char = 0;
|
||||||
max_char = ch;
|
for (cur = start, i = 0; i < slicelength; cur += step, i++) {
|
||||||
if (max_char >= kind_limit)
|
ch = PyUnicode_READ(src_kind, src_data, cur);
|
||||||
break;
|
if (ch > max_char) {
|
||||||
|
max_char = ch;
|
||||||
|
if (max_char >= kind_limit)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
max_char = 127;
|
||||||
result = PyUnicode_New(slicelength, max_char);
|
result = PyUnicode_New(slicelength, max_char);
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue