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.
This commit is contained in:
Victor Stinner 2013-06-21 19:08:06 +02:00
parent 79278bd8f6
commit f1913ca37f

View file

@ -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)
} }
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;