Kaydet (Commit) f1913ca3 authored tarafından 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.
üst 79278bd8
...@@ -979,20 +979,25 @@ r_object(RFILE *p) ...@@ -979,20 +979,25 @@ r_object(RFILE *p)
retval = NULL; retval = NULL;
break; break;
} }
buffer = PyMem_NEW(char, n); if (n != 0) {
if (buffer == NULL) { buffer = PyMem_NEW(char, n);
retval = PyErr_NoMemory(); if (buffer == NULL) {
break; retval = PyErr_NoMemory();
} break;
if (r_string(buffer, n, p) != n) { }
if (r_string(buffer, n, p) != n) {
PyMem_DEL(buffer);
PyErr_SetString(PyExc_EOFError,
"EOF read where object expected");
retval = NULL;
break;
}
v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass");
PyMem_DEL(buffer); PyMem_DEL(buffer);
PyErr_SetString(PyExc_EOFError,
"EOF read where object expected");
retval = NULL;
break;
} }
v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass"); else {
PyMem_DEL(buffer); 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