Browse Source

bpo-34303: Micro-optimizations in functools.reduce() (GH-8598)

pull/13750/head
Sergey Fedoseev 7 years ago
committed by Raymond Hettinger
parent
commit
e5f6207ba6
  1. 2
      Misc/NEWS.d/next/Library/2018-08-03-09-47-20.bpo-34303.tOE2HP.rst
  2. 9
      Modules/_functoolsmodule.c

2
Misc/NEWS.d/next/Library/2018-08-03-09-47-20.bpo-34303.tOE2HP.rst

@ -0,0 +1,2 @@
Performance of :func:`functools.reduce` is slightly improved. Patch by
Sergey Fedoseev.

9
Modules/_functoolsmodule.c

@ -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;
}
}
}

Loading…
Cancel
Save