[Python-checkins] cpython: Reuse surrogate macros in UTF-16 decoder

victor.stinner python-checkins at python.org
Sun Nov 20 22:53:23 CET 2011


http://hg.python.org/cpython/rev/99e2ccd351c0
changeset:   73636:99e2ccd351c0
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Sun Nov 20 18:40:27 2011 +0100
summary:
  Reuse surrogate macros in UTF-16 decoder

files:
  Objects/unicodeobject.c |  9 ++++-----
  1 files changed, 4 insertions(+), 5 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -5339,13 +5339,12 @@
             endinpos = ((const char *)e) + 1 - starts;
             goto utf16Error;
         }
-        if (0xD800 <= ch && ch <= 0xDBFF) {
-            Py_UNICODE ch2 = (q[ihi] << 8) | q[ilo];
+        if (Py_UNICODE_IS_HIGH_SURROGATE(ch)) {
+            Py_UCS4 ch2 = (q[ihi] << 8) | q[ilo];
             q += 2;
-            if (0xDC00 <= ch2 && ch2 <= 0xDFFF) {
+            if (Py_UNICODE_IS_LOW_SURROGATE(ch2)) {
                 if (unicode_putchar(&unicode, &outpos,
-                                    (((ch & 0x3FF)<<10) |
-                                     (ch2 & 0x3FF)) + 0x10000) < 0)
+                                    Py_UNICODE_JOIN_SURROGATES(ch, ch2)) < 0)
                     goto onError;
                 continue;
             }

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


More information about the Python-checkins mailing list