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 ab6a894
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions env/syspart.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ 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)
{
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;
}

0 comments on commit ab6a894

Please sign in to comment.