Prechádzať zdrojové kódy

u-a: Compute unchanging select choice variables just once

Instead of computing them on every loop, do so only once before entering
the loop.
Guillem Jover 13 rokov pred
rodič
commit
39cc848a22
1 zmenil súbory, kde vykonal 7 pridanie a 6 odobranie
  1. 7 6
      utils/update-alternatives.c

+ 7 - 6
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("------------------------------------------------------------");