cpython: d565310e7ae3 (original) (raw)
Mercurial > cpython
changeset 87654:d565310e7ae3
Issue #17897: Optimized unpickle prefetching. [#17897]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Sat, 30 Nov 2013 23:15:38 +0200 |
parents | 1ceb6f84b617 |
children | f20d966dc499 |
files | Misc/NEWS Modules/_pickle.c |
diffstat | 2 files changed, 27 insertions(+), 33 deletions(-)[+] [-] Misc/NEWS 2 Modules/_pickle.c 58 |
line wrap: on
line diff
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -18,6 +18,8 @@ Core and Builtins Library ------- +- Issue #17897: Optimized unpickle prefetching. +
- Issue #3693: Make the error message more helpful when the array.array() constructor is given a str. Move the array module typecode documentation to the docstring of the constructor.
--- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -1121,7 +1121,7 @@ static Py_ssize_t _Unpickler_ReadFromFile(UnpicklerObject *self, Py_ssize_t n) { PyObject *data;
assert(self->read != NULL); @@ -1134,7 +1134,29 @@ static Py_ssize_t Py_DECREF(empty_tuple); } else {
PyObject *len = PyLong_FromSsize_t(n);[](#l2.16)
PyObject *len;[](#l2.17)
/* Prefetch some data without advancing the file pointer, if possible */[](#l2.18)
if (self->peek && n < PREFETCH) {[](#l2.19)
len = PyLong_FromSsize_t(PREFETCH);[](#l2.20)
if (len == NULL)[](#l2.21)
return -1;[](#l2.22)
data = _Pickle_FastCall(self->peek, len);[](#l2.23)
if (data == NULL) {[](#l2.24)
if (!PyErr_ExceptionMatches(PyExc_NotImplementedError))[](#l2.25)
return -1;[](#l2.26)
/* peek() is probably not supported by the given file object */[](#l2.27)
PyErr_Clear();[](#l2.28)
Py_CLEAR(self->peek);[](#l2.29)
}[](#l2.30)
else {[](#l2.31)
read_size = _Unpickler_SetStringInput(self, data);[](#l2.32)
Py_DECREF(data);[](#l2.33)
self->prefetched_idx = 0;[](#l2.34)
if (n <= read_size)[](#l2.35)
return n;[](#l2.36)
}[](#l2.37)
}[](#l2.38)
len = PyLong_FromSsize_t(n);[](#l2.39) if (len == NULL)[](#l2.40) return -1;[](#l2.41) data = _Pickle_FastCall(self->read, len);[](#l2.42)
@@ -1142,38 +1164,8 @@ static Py_ssize_t if (data == NULL) return -1;
- /* Prefetch some data without advancing the file pointer, if possible */
- if (self->peek) {
PyObject *len, *prefetched;[](#l2.49)
len = PyLong_FromSsize_t(PREFETCH);[](#l2.50)
if (len == NULL) {[](#l2.51)
Py_DECREF(data);[](#l2.52)
return -1;[](#l2.53)
}[](#l2.54)
prefetched = _Pickle_FastCall(self->peek, len);[](#l2.55)
if (prefetched == NULL) {[](#l2.56)
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {[](#l2.57)
/* peek() is probably not supported by the given file object */[](#l2.58)
PyErr_Clear();[](#l2.59)
Py_CLEAR(self->peek);[](#l2.60)
}[](#l2.61)
else {[](#l2.62)
Py_DECREF(data);[](#l2.63)
return -1;[](#l2.64)
}[](#l2.65)
}[](#l2.66)
else {[](#l2.67)
assert(PyBytes_Check(prefetched));[](#l2.68)
prefetched_size = PyBytes_GET_SIZE(prefetched);[](#l2.69)
PyBytes_ConcatAndDel(&data, prefetched);[](#l2.70)
if (data == NULL)[](#l2.71)
return -1;[](#l2.72)
}[](#l2.73)
- }