Quellcode durchsuchen

u-a: Move alternative map loading to the actions that make use of them

This will reduce start up time, by not doing unneeded operations.
Guillem Jover vor 15 Jahren
Ursprung
Commit
abda47fbe8
1 geänderte Dateien mit 15 neuen und 10 gelöschten Zeilen
  1. 15 10
      utils/update-alternatives.c

+ 15 - 10
utils/update-alternatives.c

@@ -2100,8 +2100,6 @@ main(int argc, char **argv)
 	struct fileset *fileset = NULL;
 	struct fileset *fileset = NULL;
 	/* Path of alternative we are offering. */
 	/* Path of alternative we are offering. */
 	char *path = NULL, *current_choice = NULL;
 	char *path = NULL, *current_choice = NULL;
-	/* Alternatives maps for checks */
-	struct alternative_map *alt_map_obj, *alt_map_links, *alt_map_parent;
 	const char *new_choice = NULL;
 	const char *new_choice = NULL;
 	int i = 0;
 	int i = 0;
 
 
@@ -2251,22 +2249,21 @@ main(int argc, char **argv)
 		           "--config, --set, --set-selections, --install, "
 		           "--config, --set, --set-selections, --install, "
 		           "--remove, --all, --remove-all or --auto"));
 		           "--remove, --all, --remove-all or --auto"));
 
 
-	/* Load infos about all alternatives to be able to check for mistakes. */
-	alt_map_obj = alternative_map_new(NULL, NULL);
-	alternative_map_load_names(alt_map_obj);
-
-	alt_map_links = alternative_map_new(NULL, NULL);
-	alt_map_parent = alternative_map_new(NULL, NULL);
-	alternative_map_load_tree(alt_map_links, alt_map_parent);
-
 	/* Check that caller don't mix links between alternatives and don't mix
 	/* Check that caller don't mix links between alternatives and don't mix
 	 * alternatives between slave/master, and that the various parameters
 	 * alternatives between slave/master, and that the various parameters
 	 * are fine. */
 	 * are fine. */
 	if (strcmp(action, "install") == 0) {
 	if (strcmp(action, "install") == 0) {
+		struct alternative_map *alt_map_links, *alt_map_parent;
 		struct alternative *found;
 		struct alternative *found;
 		struct stat st;
 		struct stat st;
 		struct slave_link *sl;
 		struct slave_link *sl;
 
 
+		/* Load information about all alternatives to be able to
+		 * check for mistakes. */
+		alt_map_links = alternative_map_new(NULL, NULL);
+		alt_map_parent = alternative_map_new(NULL, NULL);
+		alternative_map_load_tree(alt_map_links, alt_map_parent);
+
 		found = alternative_map_find(alt_map_parent,
 		found = alternative_map_find(alt_map_parent,
 		                             inst_alt->master_name);
 		                             inst_alt->master_name);
 		if (found && strcmp(found->master_name,
 		if (found && strcmp(found->master_name,
@@ -2358,8 +2355,12 @@ main(int argc, char **argv)
 		config_all();
 		config_all();
 		exit(0);
 		exit(0);
 	} else if (strcmp(action, "get-selections") == 0) {
 	} else if (strcmp(action, "get-selections") == 0) {
+		struct alternative_map *alt_map_obj;
 		struct alternative_map *am;
 		struct alternative_map *am;
 
 
+		alt_map_obj = alternative_map_new(NULL, NULL);
+		alternative_map_load_names(alt_map_obj);
+
 		for (am = alt_map_obj; am && am->item; am = am->next) {
 		for (am = alt_map_obj; am && am->item; am = am->next) {
 			char *current;
 			char *current;
 
 
@@ -2372,7 +2373,11 @@ main(int argc, char **argv)
 
 
 		exit(0);
 		exit(0);
 	} else if (strcmp(action, "set-selections") == 0) {
 	} else if (strcmp(action, "set-selections") == 0) {
+		struct alternative_map *alt_map_obj;
+
 		log_msg("run with %s", get_argv_string(argc, argv));
 		log_msg("run with %s", get_argv_string(argc, argv));
+		alt_map_obj = alternative_map_new(NULL, NULL);
+		alternative_map_load_names(alt_map_obj);
 		alternative_set_selections(alt_map_obj, stdin, _("<standard input>"));
 		alternative_set_selections(alt_map_obj, stdin, _("<standard input>"));
 		exit(0);
 		exit(0);
 	}
 	}