From c81a2806ffd7a7946f053cbafc4fd5d8b947accc Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 27 Dec 2019 21:11:29 +0100 Subject: [PATCH] xbps_transaction_prepare: optimize a bit. If all packages in transaction are on hold, there's no need to check for conflicts, shlibs, etc. This makes `xbps-install -un` work faster on my system: ~0.450ms -> ~0.250ms There's still room for more improvements :-) --- lib/transaction_prepare.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/transaction_prepare.c b/lib/transaction_prepare.c index 425fca42..5e3aa052 100644 --- a/lib/transaction_prepare.c +++ b/lib/transaction_prepare.c @@ -276,8 +276,10 @@ int xbps_transaction_prepare(struct xbps_handle *xhp) { xbps_array_t array, pkgs, edges; + xbps_dictionary_t tpkgd; unsigned int i, cnt; int rv = 0; + bool all_on_hold = true; if ((rv = xbps_transaction_init(xhp)) != 0) return rv; @@ -327,6 +329,24 @@ xbps_transaction_prepare(struct xbps_handle *xhp) } xbps_object_release(edges); + /* + * If all pkgs in transaction are on hold, no need to check + * for anything else. + */ + all_on_hold = true; + for (i = 0; i < cnt; i++) { + const char *action; + + tpkgd = xbps_array_get(pkgs, i); + xbps_dictionary_get_cstring_nocopy(tpkgd, "transaction", &action); + if (strcmp(action, "hold")) { + all_on_hold = false; + break; + } + } + if (all_on_hold) + goto out; + /* * Check for packages to be replaced. */ @@ -365,6 +385,7 @@ xbps_transaction_prepare(struct xbps_handle *xhp) return ENOEXEC; } } +out: /* * Add transaction stats for total download/installed size, * number of packages to be installed, updated, configured