bpo-34303: Micro-optimizations in functools.reduce() (GH-8598)
This commit is contained in:
parent
3b57f50efc
commit
e5f6207ba6
@ -0,0 +1,2 @@
|
|||||||
|
Performance of :func:`functools.reduce` is slightly improved. Patch by
|
||||||
|
Sergey Fedoseev.
|
@ -626,10 +626,13 @@ functools_reduce(PyObject *self, PyObject *args)
|
|||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
result = op2;
|
result = op2;
|
||||||
else {
|
else {
|
||||||
PyTuple_SetItem(args, 0, result);
|
/* Update the args tuple in-place */
|
||||||
PyTuple_SetItem(args, 1, op2);
|
assert(args->ob_refcnt == 1);
|
||||||
if ((result = PyEval_CallObject(func, args)) == NULL)
|
Py_XSETREF(_PyTuple_ITEMS(args)[0], result);
|
||||||
|
Py_XSETREF(_PyTuple_ITEMS(args)[1], op2);
|
||||||
|
if ((result = PyObject_Call(func, args, NULL)) == NULL) {
|
||||||
goto Fail;
|
goto Fail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user