diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-12 23:17:06 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-12 23:17:06 (GMT) |
commit | 55c991197b8dc971c1358b2b8e71fc9eaf3970c9 (patch) | |
tree | 8807ede165c8ed24feef5c67fe2e36e9d2417681 | |
parent | 127226ba6958fbfe69d74220b9bda70af9fdafd8 (diff) | |
download | cpython-55c991197b8dc971c1358b2b8e71fc9eaf3970c9.zip cpython-55c991197b8dc971c1358b2b8e71fc9eaf3970c9.tar.gz cpython-55c991197b8dc971c1358b2b8e71fc9eaf3970c9.tar.bz2 |
Optimize unicode_subscript() for step != 1 and ascii strings
-rw-r--r-- | Objects/unicodeobject.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index cb03300..204e5d9 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -12614,18 +12614,22 @@ unicode_subscript(PyUnicodeObject* self, PyObject* item) start, start + slicelength); } /* General case */ - max_char = 0; src_kind = PyUnicode_KIND(self); - kind_limit = kind_maxchar_limit(src_kind); src_data = PyUnicode_DATA(self); - for (cur = start, i = 0; i < slicelength; cur += step, i++) { - ch = PyUnicode_READ(src_kind, src_data, cur); - if (ch > max_char) { - max_char = ch; - if (max_char >= kind_limit) - break; + if (!PyUnicode_IS_ASCII(self)) { + kind_limit = kind_maxchar_limit(src_kind); + max_char = 0; + for (cur = start, i = 0; i < slicelength; cur += step, i++) { + ch = PyUnicode_READ(src_kind, src_data, cur); + if (ch > max_char) { + max_char = ch; + if (max_char >= kind_limit) + break; + } } } + else + max_char = 127; result = PyUnicode_New(slicelength, max_char); if (result == NULL) return NULL; |