bootspec: only sort entries list once
authorLennart Poettering <lennart@poettering.net>
Wed, 6 Feb 2019 16:53:43 +0000 (17:53 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 1 Mar 2019 11:41:32 +0000 (12:41 +0100)
Instead of re-sorting entries list each time we loaded enrties from a
specific source, let's just sort them once at the end.

src/shared/bootspec.c

index ee285b9..2db6425 100644 (file)
@@ -238,7 +238,6 @@ static int boot_entries_find(
 
         _cleanup_strv_free_ char **files = NULL;
         size_t n_allocated = *n_entries;
-        bool added = false;
         char **f;
         int r;
 
@@ -260,12 +259,8 @@ static int boot_entries_find(
                         continue;
 
                 (*n_entries) ++;
-                added = true;
         }
 
-        if (added)
-                typesafe_qsort(*entries, *n_entries, boot_entry_compare);
-
         return 0;
 }
 
@@ -444,7 +439,6 @@ static int boot_entries_find_unified(
 
         _cleanup_(closedirp) DIR *d = NULL;
         size_t n_allocated = *n_entries;
-        bool added = false;
         struct dirent *de;
         int r;
 
@@ -499,12 +493,8 @@ static int boot_entries_find_unified(
                         continue;
 
                 (*n_entries) ++;
-                added = true;
         }
 
-        if (added)
-                typesafe_qsort(*entries, *n_entries, boot_entry_compare);
-
         return 0;
 }
 
@@ -654,6 +644,8 @@ int boot_entries_load_config(
                         return r;
         }
 
+        typesafe_qsort(config->entries, config->n_entries, boot_entry_compare);
+
         r = boot_entries_uniquify(config->entries, config->n_entries);
         if (r < 0)
                 return log_error_errno(r, "Failed to uniquify boot entries: %m");