Skip to content

Commit 7521069

Browse files
committed
Issue #27128: _pickle uses fast call
Use _PyObject_FastCall() to avoid the creation of temporary tuple.
1 parent f7a4c48 commit 7521069

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

Modules/_pickle.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ static PyObject *
345345
_Pickle_FastCall(PyObject *func, PyObject *obj)
346346
{
347347
PyObject *result;
348-
PyObject *arg_tuple = PyTuple_New(1);
349348

350349
/* Note: this function used to reuse the argument tuple. This used to give
351350
a slight performance boost with older pickle implementations where many
@@ -358,13 +357,8 @@ _Pickle_FastCall(PyObject *func, PyObject *obj)
358357
significantly reduced the number of function calls we do. Thus, the
359358
benefits became marginal at best. */
360359

361-
if (arg_tuple == NULL) {
362-
Py_DECREF(obj);
363-
return NULL;
364-
}
365-
PyTuple_SET_ITEM(arg_tuple, 0, obj);
366-
result = PyObject_Call(func, arg_tuple, NULL);
367-
Py_CLEAR(arg_tuple);
360+
result = _PyObject_FastCall(func, &obj, 1, NULL);
361+
Py_DECREF(obj);
368362
return result;
369363
}
370364

@@ -1157,9 +1151,7 @@ _Unpickler_ReadFromFile(UnpicklerObject *self, Py_ssize_t n)
11571151
return -1;
11581152

11591153
if (n == READ_WHOLE_LINE) {
1160-
PyObject *empty_tuple = PyTuple_New(0);
1161-
data = PyObject_Call(self->readline, empty_tuple, NULL);
1162-
Py_DECREF(empty_tuple);
1154+
data = _PyObject_FastCall(self->readline, NULL, 0, NULL);
11631155
}
11641156
else {
11651157
PyObject *len;
@@ -3956,10 +3948,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
39563948
/* Check for a __reduce__ method. */
39573949
reduce_func = _PyObject_GetAttrId(obj, &PyId___reduce__);
39583950
if (reduce_func != NULL) {
3959-
PyObject *empty_tuple = PyTuple_New(0);
3960-
reduce_value = PyObject_Call(reduce_func, empty_tuple,
3961-
NULL);
3962-
Py_DECREF(empty_tuple);
3951+
reduce_value = _PyObject_FastCall(reduce_func, NULL, 0, NULL);
39633952
}
39643953
else {
39653954
PyErr_Format(st->PicklingError,

0 commit comments

Comments
 (0)