[Python-checkins] cpython: Optimize unicode_subscript() for step != 1 and ascii strings

victor.stinner python-checkins at python.org
Thu Oct 13 01:17:31 CEST 2011


http://hg.python.org/cpython/rev/b1ec313b10ae
changeset:   72906:b1ec313b10ae
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Thu Oct 13 01:17:06 2011 +0200
summary:
  Optimize unicode_subscript() for step != 1 and ascii strings

files:
  Objects/unicodeobject.c |  24 ++++++++++++++----------
  1 files changed, 14 insertions(+), 10 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -12614,18 +12614,22 @@
                                        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;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list