Skip to content

Commit

Permalink
bpo-34303: Micro-optimizations in functools.reduce() (pythonGH-8598)
Browse files Browse the repository at this point in the history
  • Loading branch information
sir-sigurd authored and rhettinger committed Jun 1, 2019
1 parent 3b57f50 commit e5f6207
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Performance of :func:`functools.reduce` is slightly improved. Patch by
Sergey Fedoseev.
9 changes: 6 additions & 3 deletions Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,13 @@ functools_reduce(PyObject *self, PyObject *args)
if (result == NULL)
result = op2;
else {
PyTuple_SetItem(args, 0, result);
PyTuple_SetItem(args, 1, op2);
if ((result = PyEval_CallObject(func, args)) == NULL)
/* Update the args tuple in-place */
assert(args->ob_refcnt == 1);
Py_XSETREF(_PyTuple_ITEMS(args)[0], result);
Py_XSETREF(_PyTuple_ITEMS(args)[1], op2);
if ((result = PyObject_Call(func, args, NULL)) == NULL) {
goto Fail;
}
}
}

Expand Down

0 comments on commit e5f6207

Please sign in to comment.