Skip to content

Commit

Permalink
Optimize filter_cfg_parts
Browse files Browse the repository at this point in the history
First, we don't need to scan the complete volume list once we found one
on the boot medium. Second, we can now rely on the fact that volumes on
the boot medium come first and drop any sorting logic.

Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
jan-kiszka committed Dec 9, 2024
1 parent 3602b73 commit b5eb1df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
19 changes: 6 additions & 13 deletions env/syspart.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,7 @@ EFI_STATUS enumerate_cfg_parts(UINTN *config_volumes, UINTN *numHandles)
return EFI_SUCCESS;
}

static VOID swap_uintn(UINTN *a, UINTN *b)
{
UINTN tmp;
tmp = *a;
*a = *b;
*b = tmp;
}

UINTN filter_cfg_parts(UINTN *config_volumes, UINTN numHandles)
UINTN filter_cfg_parts(const UINTN *config_volumes, UINTN numHandles)
{
BOOLEAN use_envs_on_bootmedium_only = FALSE;

Expand All @@ -69,6 +61,7 @@ UINTN filter_cfg_parts(UINTN *config_volumes, UINTN numHandles)

if (v->onbootmedium) {
use_envs_on_bootmedium_only = TRUE;
break;
};
}

Expand All @@ -78,18 +71,18 @@ UINTN filter_cfg_parts(UINTN *config_volumes, UINTN numHandles)
}

INFO(L"Booting with environments from boot medium only.\n");
UINTN num_sorted = 0;
UINTN num_filtered = 0;
for (UINTN j = 0; j < numHandles; j++) {
UINTN cvi = config_volumes[j];
VOLUME_DESC *v = &volumes[cvi];

if (v->onbootmedium) {
swap_uintn(&config_volumes[j],
&config_volumes[num_sorted++]);
/* boot volumes are guaranteed to be first in the list */
num_filtered++;
} else {
WARNING(L"Ignoring config on volume #%d\n", cvi);
}
}

return num_sorted;
return num_filtered;
}
2 changes: 1 addition & 1 deletion include/syspart.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
(file)->Read((file), (len), (buffer))

EFI_STATUS enumerate_cfg_parts(UINTN *config_volumes, UINTN *maxHandles);
UINTN filter_cfg_parts(UINTN *config_volumes, UINTN maxHandles);
UINTN filter_cfg_parts(const UINTN *config_volumes, UINTN maxHandles);

0 comments on commit b5eb1df

Please sign in to comment.