summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2019-06-01 20:32:18 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2019-06-01 20:32:17 (GMT)
commite5f6207ba6cb510d9370519ba869296be01787be (patch)
tree82f73914776a321563cb6f0c7886994825fa9e01 /Modules
parent3b57f50efc16c65df96914ec53bc8d3dc28e18b6 (diff)
downloadcpython-e5f6207ba6cb510d9370519ba869296be01787be.zip
cpython-e5f6207ba6cb510d9370519ba869296be01787be.tar.gz
cpython-e5f6207ba6cb510d9370519ba869296be01787be.tar.bz2
bpo-34303: Micro-optimizations in functools.reduce() (GH-8598)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_functoolsmodule.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index aca5bad..a101363 100644
--- a/Modules/_functoolsmodule.c
+++ b/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;
+ }
}
}