From 1cbc2a14f2731a55e041253bcd9322407a9fd258 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Thu, 6 Sep 2012 10:48:51 +0300 Subject: [PATCH] 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... --- lib/rpminstall.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/rpminstall.c b/lib/rpminstall.c index 41e796a..a3623fd 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); -- 2.7.4