[Python-checkins] cpython: cave to those who like readable code

benjamin.peterson python-checkins at python.org
Wed Nov 23 02:06:34 CET 2011


http://hg.python.org/cpython/rev/5c70f5215c24
changeset:   73714:5c70f5215c24
parent:      73697:77ab830930ae
user:        Benjamin Peterson <benjamin at python.org>
date:        Tue Nov 22 19:05:49 2011 -0600
summary:
  cave to those who like readable code

files:
  Objects/unicodeobject.c |  16 +++++++++++++++-
  1 files changed, 15 insertions(+), 1 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -6164,7 +6164,21 @@
     kind = PyUnicode_KIND(unicode);
     data = PyUnicode_DATA(unicode);
     len = PyUnicode_GET_LENGTH(unicode);
-    expandsize = kind * 2 + 2;
+    expandsize = 0;
+    switch (kind) {
+    case PyUnicode_1BYTE_KIND:
+        expandsize = 4;
+        break;
+    case PyUnicode_2BYTE_KIND:
+        expandsize = 6;
+        break;
+    case PyUnicode_4BYTE_KIND:
+        expandsize = 10;
+        break;
+    default:
+        assert(0);
+        break;
+    }
 
     if (len > PY_SSIZE_T_MAX / expandsize)
         return PyErr_NoMemory();

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


More information about the Python-checkins mailing list