diff options
author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2019-02-25 21:59:12 +0500 |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2019-02-25 17:59:12 +0100 |
commit | 234531b4462b20d668762bd78406fd2ebab129c9 (patch) | |
tree | f0a93cbdf6ebf42055498ea9533891cec0680bcf /Objects/structseq.c | |
parent | 55e335d7d59be44819c6b672d258e2d5feb1e633 (diff) | |
download | cpython-git-234531b4462b20d668762bd78406fd2ebab129c9.tar.gz |
bpo-36030: Add _PyTuple_FromArray() function (GH-11954)
Diffstat (limited to 'Objects/structseq.c')
-rw-r--r-- | Objects/structseq.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/Objects/structseq.c b/Objects/structseq.c index cf94155f18..56b06c707f 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -2,6 +2,7 @@ and posixmodule for example uses. */ #include "Python.h" +#include "pycore_tupleobject.h" #include "structmember.h" static const char visible_length_key[] = "n_sequence_fields"; @@ -250,7 +251,7 @@ structseq_reduce(PyStructSequence* self, PyObject *Py_UNUSED(ignored)) n_fields = REAL_SIZE(self); n_visible_fields = VISIBLE_SIZE(self); n_unnamed_fields = UNNAMED_FIELDS(self); - tup = PyTuple_New(n_visible_fields); + tup = _PyTuple_FromArray(self->ob_item, n_visible_fields); if (!tup) goto error; @@ -258,12 +259,7 @@ structseq_reduce(PyStructSequence* self, PyObject *Py_UNUSED(ignored)) if (!dict) goto error; - for (i = 0; i < n_visible_fields; i++) { - Py_INCREF(self->ob_item[i]); - PyTuple_SET_ITEM(tup, i, self->ob_item[i]); - } - - for (; i < n_fields; i++) { + for (i = n_visible_fields; i < n_fields; i++) { const char *n = Py_TYPE(self)->tp_members[i-n_unnamed_fields].name; if (PyDict_SetItemString(dict, n, self->ob_item[i]) < 0) goto error; |