diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2012-09-06 10:48:51 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2012-09-06 10:48:51 +0300 |
commit | 1cbc2a14f2731a55e041253bcd9322407a9fd258 (patch) | |
tree | 3c9489f74279b65e95aabf08b3315d758ac44828 | |
parent | fddfee17c3c4e19269665800d557d3452cbde162 (diff) | |
download | librpm-tizen-1cbc2a14f2731a55e041253bcd9322407a9fd258.tar.gz librpm-tizen-1cbc2a14f2731a55e041253bcd9322407a9fd258.tar.bz2 librpm-tizen-1cbc2a14f2731a55e041253bcd9322407a9fd258.zip |
Avoid double iteration on 'rpm -e' now that iterator count works
- While harmless, having to count on one and act on another iteration
gets expensive when there are lots of labels specified. Especially
as the iterator initialization can already load the same headers
multiple times, sigh...
-rw-r--r-- | lib/rpminstall.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/lib/rpminstall.c b/lib/rpminstall.c index 41e796a05..a3623fd3a 100644 --- a/lib/rpminstall.c +++ b/lib/rpminstall.c @@ -646,17 +646,10 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv) qfmt = rpmExpand("%{?_query_all_fmt}\n", NULL); for (arg = argv; *arg; arg++) { - rpmdbMatchIterator mi; - int matches = 0; + rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0); + int matches = rpmdbGetIteratorCount(mi); int erasing = 1; - /* Iterator count isn't reliable with labels, count manually... */ - mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0); - while (rpmdbNextIterator(mi) != NULL) { - matches++; - } - rpmdbFreeIterator(mi); - if (! matches) { rpmlog(RPMLOG_ERR, _("package %s is not installed\n"), *arg); numFailed++; @@ -671,7 +664,6 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv) erasing = 0; } - mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0); while ((h = rpmdbNextIterator(mi)) != NULL) { if (erasing) { (void) rpmtsAddEraseElement(ts, h, -1); @@ -682,8 +674,8 @@ int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv) free(nevra); } } - rpmdbFreeIterator(mi); } + rpmdbFreeIterator(mi); } free(qfmt); |