[Python-checkins] cpython: Speedup find_maxchar_surrogates() for 32-bit wchar_t

victor.stinner python-checkins at python.org
Wed Oct 5 14:13:33 CEST 2011


http://hg.python.org/cpython/rev/b8d4c4a89065
changeset:   72686:b8d4c4a89065
user:        Victor Stinner <vstinner at wyplay.com>
date:        Wed Oct 05 14:02:44 2011 +0200
summary:
  Speedup find_maxchar_surrogates() for 32-bit wchar_t

If we have at least one character in U+10000-U+10FFFF, we know that we must use
PyUnicode_4BYTE_KIND kind.

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


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1060,19 +1060,17 @@
     const wchar_t *iter;
 
     assert(num_surrogates != NULL && maxchar != NULL);
-    if (num_surrogates == NULL || maxchar == NULL) {
-        PyErr_SetString(PyExc_SystemError,
-                        "unexpected NULL arguments to "
-                        "PyUnicode_FindMaxCharAndNumSurrogatePairs");
-        return -1;
-    }
-
     *num_surrogates = 0;
     *maxchar = 0;
 
     for (iter = begin; iter < end; ) {
-        if (*iter > *maxchar)
+        if (*iter > *maxchar) {
             *maxchar = *iter;
+#if SIZEOF_WCHAR_T != 2
+            if (*maxchar >= 0x10000)
+                return 0;
+#endif
+        }
 #if SIZEOF_WCHAR_T == 2
         if (*iter >= 0xD800 && *iter <= 0xDBFF
             && (iter+1) < end && iter[1] >= 0xDC00 && iter[1] <= 0xDFFF)

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


More information about the Python-checkins mailing list