summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2013-09-02 11:24:54 +0200
committerGuillem Jover <guillem@debian.org>2013-10-16 05:20:19 +0200
commit39cc848a227998a1ba6737acea8b15c0f5882899 (patch)
treec3e9f86692669dc8df0bc6afb414b72887b815c0 /utils
parent6cfc3842df339504e9327e1b90fafc6201fddbf1 (diff)
downloaddpkg-39cc848a227998a1ba6737acea8b15c0f5882899.tar.gz
u-a: Compute unchanging select choice variables just once
Instead of computing them on every loop, do so only once before entering the loop.
Diffstat (limited to 'utils')
-rw-r--r--utils/update-alternatives.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c
index 7730a91db..f401607ed 100644
--- a/utils/update-alternatives.c
+++ b/utils/update-alternatives.c
@@ -1570,25 +1570,26 @@ alternative_select_choice(struct alternative *a)
const char *current;
char *ret, selection[_POSIX_PATH_MAX];
struct fileset *best, *fs;
+ int n_choices;
int len, idx;
+ n_choices = alternative_choices_count(a);
current = alternative_get_current(a);
best = alternative_get_best(a);
assert(best);
+ len = 15;
+ for (fs = a->choices; fs; fs = fs->next)
+ len = max(len, (int)strlen(fs->master_file) + 1);
+
for (;;) {
const char *mark;
- int n_choices;
-
- n_choices = alternative_choices_count(a);
pr(P_("There is %d choice for the alternative %s (providing %s).",
"There are %d choices for the alternative %s (providing %s).",
n_choices), n_choices, a->master_name, a->master_link);
printf("\n");
- len = 15;
- for (fs = a->choices; fs; fs = fs->next)
- len = max(len, (int)strlen(fs->master_file) + 1);
+
pr(" %-12.12s %-*.*s %-10.10s %s", _("Selection"), len, len,
_("Path"), _("Priority"), _("Status"));
pr("------------------------------------------------------------");