diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2012-03-08 10:02:51 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2012-03-08 10:02:51 +0200 |
commit | 1432d5338336e6000263ad5d6a5836574e85ff91 (patch) | |
tree | 98ed39c57deab0161d79eba4b8e73868567a1df3 /python | |
parent | 5cf61c9a75a573238fdeba7332a6bcad25b86953 (diff) | |
download | librpm-tizen-1432d5338336e6000263ad5d6a5836574e85ff91.tar.gz librpm-tizen-1432d5338336e6000263ad5d6a5836574e85ff91.tar.bz2 librpm-tizen-1432d5338336e6000263ad5d6a5836574e85ff91.zip |
Optimize header data python conversion for array tags a bit
- We know the array size beforehand, allocate the entire array
at once and set the elements instead of appending one by one.
This is (an obvious) and well-measurable, if not a huge, win.
Diffstat (limited to 'python')
-rw-r--r-- | python/rpmtd-py.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/python/rpmtd-py.c b/python/rpmtd-py.c index 026f6c711..7655755f0 100644 --- a/python/rpmtd-py.c +++ b/python/rpmtd-py.c @@ -43,18 +43,18 @@ PyObject *rpmtd_AsPyobj(rpmtd td) } if (array) { - res = PyList_New(0); + int ix; + res = PyList_New(rpmtdCount(td)); if (!res) { return NULL; } - while (rpmtdNext(td) >= 0) { + while ((ix = rpmtdNext(td)) >= 0) { PyObject *item = rpmtd_ItemAsPyobj(td, tclass); if (!item) { Py_DECREF(res); return NULL; } - PyList_Append(res, item); - Py_DECREF(item); + PyList_SET_ITEM(res, ix, item); } } else { res = rpmtd_ItemAsPyobj(td, tclass); |