Commit 8cdfe9de authored by Victor Stinner's avatar Victor Stinner

marshal: optimize parsing of empty Unicode strings

Don't create a temporary buffer of zeroy byte nor call r_string() if the length
is zero, create directly the empty string.
parent 867aa61b
...@@ -979,6 +979,7 @@ r_object(RFILE *p) ...@@ -979,6 +979,7 @@ r_object(RFILE *p)
retval = NULL; retval = NULL;
break; break;
} }
if (n != 0) {
buffer = PyMem_NEW(char, n); buffer = PyMem_NEW(char, n);
if (buffer == NULL) { if (buffer == NULL) {
retval = PyErr_NoMemory(); retval = PyErr_NoMemory();
...@@ -993,6 +994,10 @@ r_object(RFILE *p) ...@@ -993,6 +994,10 @@ r_object(RFILE *p)
} }
v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass"); v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass");
PyMem_DEL(buffer); PyMem_DEL(buffer);
}
else {
v = PyUnicode_New(0, 0);
}
if (type == TYPE_INTERNED) if (type == TYPE_INTERNED)
PyUnicode_InternInPlace(&v); PyUnicode_InternInPlace(&v);
retval = v; retval = v;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment