diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-06-21 17:08:06 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-06-21 17:08:06 (GMT) |
commit | f1913ca37f65190cc6f48d9a9404453a131c124a (patch) | |
tree | d3a033f435936444e6432657e9df7d3662633af3 /Python | |
parent | 79278bd8f65e58e41168575713ae182d9051d0a3 (diff) | |
download | cpython-f1913ca37f65190cc6f48d9a9404453a131c124a.zip cpython-f1913ca37f65190cc6f48d9a9404453a131c124a.tar.gz cpython-f1913ca37f65190cc6f48d9a9404453a131c124a.tar.bz2 |
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.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/marshal.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/Python/marshal.c b/Python/marshal.c index 3e13851..e519fc9 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -979,20 +979,25 @@ r_object(RFILE *p) retval = NULL; break; } - buffer = PyMem_NEW(char, n); - if (buffer == NULL) { - retval = PyErr_NoMemory(); - break; - } - if (r_string(buffer, n, p) != n) { + if (n != 0) { + buffer = PyMem_NEW(char, n); + if (buffer == NULL) { + retval = PyErr_NoMemory(); + break; + } + 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); - PyErr_SetString(PyExc_EOFError, - "EOF read where object expected"); - retval = NULL; - break; } - v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass"); - PyMem_DEL(buffer); + else { + v = PyUnicode_New(0, 0); + } if (type == TYPE_INTERNED) PyUnicode_InternInPlace(&v); retval = v; |