mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 17:06:39 +09:00
boot: generalize sorting code
Let's make this generic, so that we can reuse it elsewhere later.
This commit is contained in:
@@ -1529,7 +1529,7 @@ static VOID config_load_entries(
|
||||
}
|
||||
}
|
||||
|
||||
static INTN config_entry_compare(ConfigEntry *a, ConfigEntry *b) {
|
||||
static INTN config_entry_compare(const ConfigEntry *a, const ConfigEntry *b) {
|
||||
INTN r;
|
||||
|
||||
assert(a);
|
||||
@@ -1567,24 +1567,7 @@ static INTN config_entry_compare(ConfigEntry *a, ConfigEntry *b) {
|
||||
static VOID config_sort_entries(Config *config) {
|
||||
assert(config);
|
||||
|
||||
for (UINTN i = 1; i < config->entry_count; i++) {
|
||||
BOOLEAN more;
|
||||
|
||||
more = FALSE;
|
||||
for (UINTN k = 0; k < config->entry_count - i; k++) {
|
||||
ConfigEntry *entry;
|
||||
|
||||
if (config_entry_compare(config->entries[k], config->entries[k+1]) <= 0)
|
||||
continue;
|
||||
|
||||
entry = config->entries[k];
|
||||
config->entries[k] = config->entries[k+1];
|
||||
config->entries[k+1] = entry;
|
||||
more = TRUE;
|
||||
}
|
||||
if (!more)
|
||||
break;
|
||||
}
|
||||
sort_pointer_array((void**) config->entries, config->entry_count, (compare_pointer_func_t) config_entry_compare);
|
||||
}
|
||||
|
||||
static INTN config_entry_find(Config *config, CHAR16 *id) {
|
||||
|
||||
@@ -531,6 +531,36 @@ VOID clear_screen(UINTN attr) {
|
||||
uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
|
||||
}
|
||||
|
||||
void sort_pointer_array(
|
||||
VOID **array,
|
||||
UINTN n_members,
|
||||
compare_pointer_func_t compare) {
|
||||
|
||||
assert(array || n_members == 0);
|
||||
assert(compare);
|
||||
|
||||
if (n_members <= 1)
|
||||
return;
|
||||
|
||||
for (UINTN i = 1; i < n_members; i++) {
|
||||
BOOLEAN more = FALSE;
|
||||
|
||||
for (UINTN k = 0; k < n_members - i; k++) {
|
||||
void *entry;
|
||||
|
||||
if (compare(array[k], array[k+1]) <= 0)
|
||||
continue;
|
||||
|
||||
entry = array[k];
|
||||
array[k] = array[k+1];
|
||||
array[k+1] = entry;
|
||||
more = TRUE;
|
||||
}
|
||||
if (!more)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EFI_STATUS get_file_info_harder(
|
||||
EFI_FILE_HANDLE handle,
|
||||
EFI_FILE_INFO **ret,
|
||||
|
||||
@@ -98,6 +98,9 @@ static inline VOID *mempmem_safe(const VOID *haystack, UINTN haystack_len, const
|
||||
VOID print_at(UINTN x, UINTN y, UINTN attr, const CHAR16 *str);
|
||||
VOID clear_screen(UINTN attr);
|
||||
|
||||
typedef INTN (*compare_pointer_func_t)(const VOID *a, const VOID *b);
|
||||
void sort_pointer_array(VOID **array, UINTN n_members, compare_pointer_func_t compare);
|
||||
|
||||
EFI_STATUS get_file_info_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **ret, UINTN *ret_size);
|
||||
|
||||
EFI_STATUS readdir_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
|
||||
|
||||
Reference in New Issue
Block a user