Optimize PyUnicode_DecodeCharmap()
Avoid expensive PyUnicode_READ() and PyUnicode_WRITE(), manipulate pointers instead.
This commit is contained in:
parent
a85af502a4
commit
63d5c1a14a
|
@ -7351,27 +7351,29 @@ PyUnicode_DecodeCharmap(const char *s,
|
||||||
while (s < e) {
|
while (s < e) {
|
||||||
if (mapkind == PyUnicode_2BYTE_KIND && maplen >= 256) {
|
if (mapkind == PyUnicode_2BYTE_KIND && maplen >= 256) {
|
||||||
enum PyUnicode_Kind outkind = writer.kind;
|
enum PyUnicode_Kind outkind = writer.kind;
|
||||||
void *outdata = writer.data;
|
Py_UCS2 *mapdata_ucs2 = (Py_UCS2 *)mapdata;
|
||||||
if (outkind == PyUnicode_1BYTE_KIND) {
|
if (outkind == PyUnicode_1BYTE_KIND) {
|
||||||
|
Py_UCS1 *outdata = (Py_UCS1 *)writer.data;
|
||||||
Py_UCS4 maxchar = writer.maxchar;
|
Py_UCS4 maxchar = writer.maxchar;
|
||||||
while (s < e) {
|
while (s < e) {
|
||||||
unsigned char ch = *s;
|
ch = *s;
|
||||||
x = PyUnicode_READ(PyUnicode_2BYTE_KIND, mapdata, ch);
|
x = mapdata_ucs2[ch];
|
||||||
if (x > maxchar)
|
if (x > maxchar)
|
||||||
goto Error;
|
goto Error;
|
||||||
PyUnicode_WRITE(PyUnicode_1BYTE_KIND, outdata, writer.pos, x);
|
outdata[writer.pos] = x;
|
||||||
writer.pos++;
|
writer.pos++;
|
||||||
++s;
|
++s;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (outkind == PyUnicode_2BYTE_KIND) {
|
else if (outkind == PyUnicode_2BYTE_KIND) {
|
||||||
|
Py_UCS2 *outdata = (Py_UCS2 *)writer.data;
|
||||||
while (s < e) {
|
while (s < e) {
|
||||||
unsigned char ch = *s;
|
ch = *s;
|
||||||
x = PyUnicode_READ(PyUnicode_2BYTE_KIND, mapdata, ch);
|
x = mapdata_ucs2[ch];
|
||||||
if (x == 0xFFFE)
|
if (x == 0xFFFE)
|
||||||
goto Error;
|
goto Error;
|
||||||
PyUnicode_WRITE(PyUnicode_2BYTE_KIND, outdata, writer.pos, x);
|
outdata[writer.pos] = x;
|
||||||
writer.pos++;
|
writer.pos++;
|
||||||
++s;
|
++s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue