summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-03-08 10:17:47 +0200
committerPanu Matilainen <pmatilai@redhat.com>2012-03-08 10:17:47 +0200
commita74b9b72a6dd3d936cab2c3c858a3c293ec6fcbd (patch)
treefc2d65b70ef13c9c4d1fdb27e6376229afc41fb7 /python
parent1432d5338336e6000263ad5d6a5836574e85ff91 (diff)
downloadlibrpm-tizen-a74b9b72a6dd3d936cab2c3c858a3c293ec6fcbd.tar.gz
librpm-tizen-a74b9b72a6dd3d936cab2c3c858a3c293ec6fcbd.tar.bz2
librpm-tizen-a74b9b72a6dd3d936cab2c3c858a3c293ec6fcbd.zip
Optimize python db index instances list generation and fix related leak
- The number of entries is well know, allocate the entire list at once and set instead of appending one by one. Also cures a leak from created tuples not being decref'ed before - list set steals the reference whereas append requires an additional decref to transfer the ownership to the list.
Diffstat (limited to 'python')
-rw-r--r--python/rpmii-py.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/python/rpmii-py.c b/python/rpmii-py.c
index 51d74e824..d7713affd 100644
--- a/python/rpmii-py.c
+++ b/python/rpmii-py.c
@@ -54,7 +54,7 @@ static PyObject *
rpmii_instances(rpmiiObject * s)
{
int entries = rpmdbIndexIteratorNumPkgs(s->ii);
- PyObject * list = PyList_New(0);
+ PyObject * list = PyList_New(entries);
PyObject * tuple;
for (int i = 0; i < entries; i++) {
tuple = PyTuple_New(2);
@@ -62,7 +62,7 @@ rpmii_instances(rpmiiObject * s)
PyInt_FromLong(rpmdbIndexIteratorPkgOffset(s->ii, i)));
PyTuple_SET_ITEM(tuple, 1,
PyInt_FromLong(rpmdbIndexIteratorTagNum(s->ii, i)));
- PyList_Append(list, tuple);
+ PyList_SET_ITEM(list, i, tuple);
}
return list;
}