summaryrefslogtreecommitdiff
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-10-13 01:17:06 +0200
committerVictor Stinner <victor.stinner@haypocalc.com>2011-10-13 01:17:06 +0200
commit55c991197b8dc971c1358b2b8e71fc9eaf3970c9 (patch)
tree8807ede165c8ed24feef5c67fe2e36e9d2417681 /Objects/unicodeobject.c
parent127226ba6958fbfe69d74220b9bda70af9fdafd8 (diff)
downloadcpython-git-55c991197b8dc971c1358b2b8e71fc9eaf3970c9.tar.gz
Optimize unicode_subscript() for step != 1 and ascii strings
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index cb03300c62..204e5d9763 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;