summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-11-23 16:44:52 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-11-23 16:44:52 (GMT)
commit1518e8713d1e372284c653f254fb29cecc66d764 (patch)
treec0fe49c380c525da05f06ff5b33c2297e555b5e6 /Objects
parentd2b0217944926a0f63b5dec1d91193cc999222ee (diff)
downloadcpython-1518e8713d1e372284c653f254fb29cecc66d764.zip
cpython-1518e8713d1e372284c653f254fb29cecc66d764.tar.gz
cpython-1518e8713d1e372284c653f254fb29cecc66d764.tar.bz2
and back to the "magic" formula (with a comment) it is
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c18
1 files changed, 3 insertions, 15 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index ab59e21..2fefdbe 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -6164,21 +6164,9 @@ PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
kind = PyUnicode_KIND(unicode);
data = PyUnicode_DATA(unicode);
len = PyUnicode_GET_LENGTH(unicode);
- 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;
- }
+ /* 4 byte characters can take up 10 bytes, 2 byte characters can take up 6
+ bytes, and 1 byte characters 4. */
+ expandsize = kind * 2 + 2;
if (len > PY_SSIZE_T_MAX / expandsize)
return PyErr_NoMemory();