[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 4/5] grub-mkconfig kfreebsd: Fix quadratic algorithm for sorti
From: |
Mathieu Desnoyers |
Subject: |
[PATCH v6 4/5] grub-mkconfig kfreebsd: Fix quadratic algorithm for sorting menu items |
Date: |
Mon, 13 Jun 2022 10:08:25 -0400 |
The current implementation of the 10_kfreebsd script implements its menu
items sorting in bash with a quadratic algorithm, calling "sed", "sort",
"head", and "grep" to compare versions between individual lines, which
is annoyingly slow for kernel developers who can easily end up with
50-100 kernels in their boot partition.
This fix is ported from the 10_linux script, which has a similar
quadratic code pattern.
[ Note: this is untested. I would be grateful if anyone with a kfreebsd
environment could test it before it is merged. ]
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: debian-bsd@lists.debian.org
---
Changes since v4:
- Combine sed -e '...' -e '...' into sed -e '...; ...'
---
util/grub.d/10_kfreebsd.in | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/util/grub.d/10_kfreebsd.in b/util/grub.d/10_kfreebsd.in
index 199b20e16..0a67decaa 100644
--- a/util/grub.d/10_kfreebsd.in
+++ b/util/grub.d/10_kfreebsd.in
@@ -157,10 +157,16 @@ title_correction_code=
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
submenu_indentation=""
+# Perform a reverse version sort on the entire list.
+# Temporarily replace the '.old' suffix by ' 1' and append ' 2' for all
+# other files to order the '.old' files after their non-old counterpart
+# in reverse-sorted order.
+
+reverse_sorted_list=$(echo ${list} | tr ' ' '\n' | sed -e 's/\.old$/ 1/; /
1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$//')
+
is_top_level=true
-while [ "x$list" != "x" ] ; do
- kfreebsd=`version_find_latest $list`
+for kfreebsd in ${reverse_sorted_list}; do
gettext_printf "Found kernel of FreeBSD: %s\n" "$kfreebsd" >&2
basename=`basename $kfreebsd`
dirname=`dirname $kfreebsd`
@@ -238,8 +244,6 @@ while [ "x$list" != "x" ] ; do
if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
kfreebsd_entry "${OS}" "${version}" recovery "-s"
fi
-
- list=`echo $list | tr ' ' '\n' | fgrep -vx "$kfreebsd" | tr '\n' ' '`
done
# If at least one kernel was found, then we need to
--
2.30.2
- [PATCH v6 0/5] grub-mkconfig: Fix quadratic algorithm for sorting menu items, Mathieu Desnoyers, 2022/06/13
- [PATCH v6 2/5] grub-mkconfig linux_xen: Fix quadratic algorithm for sorting menu items, Mathieu Desnoyers, 2022/06/13
- [PATCH v6 5/5] Cleanup: grub-mkconfig_lib: remove unused version comparison functions, Mathieu Desnoyers, 2022/06/13
- [PATCH v6 4/5] grub-mkconfig kfreebsd: Fix quadratic algorithm for sorting menu items,
Mathieu Desnoyers <=
- [PATCH v6 1/5] grub-mkconfig linux: Fix quadratic algorithm for sorting menu items, Mathieu Desnoyers, 2022/06/13
- [PATCH v6 3/5] grub-mkconfig hurd: Fix quadratic algorithm for sorting menu items, Mathieu Desnoyers, 2022/06/13
- Re: [PATCH v6 0/5] grub-mkconfig: Fix quadratic algorithm for sorting menu items, Daniel Kiper, 2022/06/24