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)
retval = NULL;
break;
}
if (n != 0) {
buffer = PyMem_NEW(char, n);
if (buffer == NULL) {
retval = PyErr_NoMemory();
......@@ -993,6 +994,10 @@ r_object(RFILE *p)
}
v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass");
PyMem_DEL(buffer);
}
else {
v = PyUnicode_New(0, 0);
}
if (type == TYPE_INTERNED)
PyUnicode_InternInPlace(&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