diff options
author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2019-02-25 16:59:12 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2019-02-25 16:59:12 (GMT) |
commit | 234531b4462b20d668762bd78406fd2ebab129c9 (patch) | |
tree | f0a93cbdf6ebf42055498ea9533891cec0680bcf /Modules/itertoolsmodule.c | |
parent | 55e335d7d59be44819c6b672d258e2d5feb1e633 (diff) | |
download | cpython-234531b4462b20d668762bd78406fd2ebab129c9.zip cpython-234531b4462b20d668762bd78406fd2ebab129c9.tar.gz cpython-234531b4462b20d668762bd78406fd2ebab129c9.tar.bz2 |
bpo-36030: Add _PyTuple_FromArray() function (GH-11954)
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r-- | Modules/itertoolsmodule.c | 29 |
1 files changed, 5 insertions, 24 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index c589dd1..536f7fa 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -1,6 +1,7 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#include "pycore_tupleobject.h" #include "structmember.h" /* Itertools module written and maintained @@ -2239,15 +2240,10 @@ product_next(productobject *lz) /* Copy the previous result tuple or re-use it if available */ if (Py_REFCNT(result) > 1) { PyObject *old_result = result; - result = PyTuple_New(npools); + result = _PyTuple_FromArray(_PyTuple_ITEMS(old_result), npools); if (result == NULL) goto empty; lz->result = result; - for (i=0; i < npools; i++) { - elem = PyTuple_GET_ITEM(old_result, i); - Py_INCREF(elem); - PyTuple_SET_ITEM(result, i, elem); - } Py_DECREF(old_result); } /* Now, we've got the only copy so we can update it in-place */ @@ -2569,15 +2565,10 @@ combinations_next(combinationsobject *co) /* Copy the previous result tuple or re-use it if available */ if (Py_REFCNT(result) > 1) { PyObject *old_result = result; - result = PyTuple_New(r); + result = _PyTuple_FromArray(_PyTuple_ITEMS(old_result), r); if (result == NULL) goto empty; co->result = result; - for (i=0; i<r ; i++) { - elem = PyTuple_GET_ITEM(old_result, i); - Py_INCREF(elem); - PyTuple_SET_ITEM(result, i, elem); - } Py_DECREF(old_result); } /* Now, we've got the only copy so we can update it in-place @@ -2910,15 +2901,10 @@ cwr_next(cwrobject *co) /* Copy the previous result tuple or re-use it if available */ if (Py_REFCNT(result) > 1) { PyObject *old_result = result; - result = PyTuple_New(r); + result = _PyTuple_FromArray(_PyTuple_ITEMS(old_result), r); if (result == NULL) goto empty; co->result = result; - for (i=0; i<r ; i++) { - elem = PyTuple_GET_ITEM(old_result, i); - Py_INCREF(elem); - PyTuple_SET_ITEM(result, i, elem); - } Py_DECREF(old_result); } /* Now, we've got the only copy so we can update it in-place CPython's @@ -3258,15 +3244,10 @@ permutations_next(permutationsobject *po) /* Copy the previous result tuple or re-use it if available */ if (Py_REFCNT(result) > 1) { PyObject *old_result = result; - result = PyTuple_New(r); + result = _PyTuple_FromArray(_PyTuple_ITEMS(old_result), r); if (result == NULL) goto empty; po->result = result; - for (i=0; i<r ; i++) { - elem = PyTuple_GET_ITEM(old_result, i); - Py_INCREF(elem); - PyTuple_SET_ITEM(result, i, elem); - } Py_DECREF(old_result); } /* Now, we've got the only copy so we can update it in-place */ |