[Python-checkins] cpython: Optimize PyUnicode_DecodeCharmap()
victor.stinner
python-checkins at python.org
Tue Apr 9 22:29:24 CEST 2013
http://hg.python.org/cpython/rev/7142471a2b7c
changeset: 83219:7142471a2b7c
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Apr 09 22:13:33 2013 +0200
summary:
Optimize PyUnicode_DecodeCharmap()
Avoid expensive PyUnicode_READ() and PyUnicode_WRITE(), manipulate pointers
instead.
files:
Objects/unicodeobject.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -7351,27 +7351,29 @@
while (s < e) {
if (mapkind == PyUnicode_2BYTE_KIND && maplen >= 256) {
enum PyUnicode_Kind outkind = writer.kind;
- void *outdata = writer.data;
+ Py_UCS2 *mapdata_ucs2 = (Py_UCS2 *)mapdata;
if (outkind == PyUnicode_1BYTE_KIND) {
+ Py_UCS1 *outdata = (Py_UCS1 *)writer.data;
Py_UCS4 maxchar = writer.maxchar;
while (s < e) {
- unsigned char ch = *s;
- x = PyUnicode_READ(PyUnicode_2BYTE_KIND, mapdata, ch);
+ ch = *s;
+ x = mapdata_ucs2[ch];
if (x > maxchar)
goto Error;
- PyUnicode_WRITE(PyUnicode_1BYTE_KIND, outdata, writer.pos, x);
+ outdata[writer.pos] = x;
writer.pos++;
++s;
}
break;
}
else if (outkind == PyUnicode_2BYTE_KIND) {
+ Py_UCS2 *outdata = (Py_UCS2 *)writer.data;
while (s < e) {
- unsigned char ch = *s;
- x = PyUnicode_READ(PyUnicode_2BYTE_KIND, mapdata, ch);
+ ch = *s;
+ x = mapdata_ucs2[ch];
if (x == 0xFFFE)
goto Error;
- PyUnicode_WRITE(PyUnicode_2BYTE_KIND, outdata, writer.pos, x);
+ outdata[writer.pos] = x;
writer.pos++;
++s;
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list