All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: grub-devel@gnu.org
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Samuel Thibault <samuel.thibault@ens-lyon.org>
Subject: [RFC PATCH v3 3/5] grub-mkconfig hurd: Fix quadratic algorithm for sorting menu items
Date: Fri, 20 May 2022 10:37:39 -0400	[thread overview]
Message-ID: <20220520143741.217690-4-mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <20220520143741.217690-1-mathieu.desnoyers@efficios.com>

The current implementation of the 10_hurd 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 Hurd
  environment could test it before it is merged. ]

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
 util/grub.d/10_hurd.in | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/util/grub.d/10_hurd.in b/util/grub.d/10_hurd.in
index 2ab3a97e6..e0f290ae8 100644
--- a/util/grub.d/10_hurd.in
+++ b/util/grub.d/10_hurd.in
@@ -195,11 +195,17 @@ title_correction_code=
 # Extra indentation to add to menu entries in a submenu. We're not in a submenu
 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
 submenu_indentation=""
-is_top_level=true
 
-while [ "x$kernels" != "x" ] ; do
-  kernel=`version_find_latest $kernels`
+# Perform a reverse version sort on the entire kernels 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_kernels=$(echo ${kernels} | tr ' ' '\n' | sed -e 's/\.old$/ 1/' -e '/ 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/' -e 's/ 2$//')
 
+is_top_level=true
+
+for kernel in ${reverse_sorted_kernels}; do
   # The GRUB_DISABLE_SUBMENU option used to be different than others since it was
   # mentioned in the documentation that has to be set to 'y' instead of 'true' to
   # enable it. This caused a lot of confusion to users that set the option to 'y',
@@ -219,8 +225,6 @@ while [ "x$kernels" != "x" ] ; do
 
   hurd_entry "$kernel" advanced
   hurd_entry "$kernel" recovery
-
-  kernels=`echo $kernels | tr ' ' '\n' | fgrep -vx "$kernel" | tr '\n' ' '`
 done
 
 # If at least one kernel was found, then we need to
-- 
2.30.2



  parent reply	other threads:[~2022-05-20 14:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-20 14:37 [RFC PATCH v3 0/5] grub-mkconfig: Fix quadratic algorithm for sorting menu items Mathieu Desnoyers
2022-05-20 14:37 ` [RFC PATCH v3 1/5] grub-mkconfig linux: " Mathieu Desnoyers
2022-05-26 15:13   ` Daniel Kiper
2022-05-26 18:34     ` Mathieu Desnoyers
2022-06-08 18:10       ` Daniel Kiper
2022-05-20 14:37 ` [RFC PATCH v3 2/5] grub-mkconfig linux_xen: " Mathieu Desnoyers
2022-05-20 14:37 ` Mathieu Desnoyers [this message]
2022-05-20 14:37 ` [RFC PATCH v3 4/5] grub-mkconfig kfreebsd: " Mathieu Desnoyers
2022-05-20 14:37 ` [RFC PATCH v3 5/5] Cleanup: grub-mkconfig_lib: remove unused version comparison functions Mathieu Desnoyers
2022-05-26 21:07   ` Robbie Harwood
2022-05-27  6:07     ` Michael Chang
2022-05-27 14:56       ` Robbie Harwood
2022-05-27 21:45         ` Daniel Kiper
2022-05-30 13:31         ` Mathieu Desnoyers
2022-05-20 16:08 ` [RFC PATCH v3 0/5] grub-mkconfig: Fix quadratic algorithm for sorting menu items Mathieu Desnoyers
2022-05-26 15:24   ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220520143741.217690-4-mathieu.desnoyers@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=grub-devel@gnu.org \
    --cc=samuel.thibault@ens-lyon.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.