Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nzNFE-000843-U6 for mharc-grub-devel@gnu.org; Thu, 09 Jun 2022 14:51:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzNEv-0007sd-Nh for grub-devel@gnu.org; Thu, 09 Jun 2022 14:50:45 -0400 Received: from mail.efficios.com ([167.114.26.124]:43170) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzNEo-0000SH-QK for grub-devel@gnu.org; Thu, 09 Jun 2022 14:50:38 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 3BC33412D45; Thu, 9 Jun 2022 14:50:29 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 0C8JmnxGIaVG; Thu, 9 Jun 2022 14:50:28 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 01BB64128F5; Thu, 9 Jun 2022 14:50:28 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 01BB64128F5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1654800628; bh=4igpOCqE4ayKZMBVdPlfQA38h2eG71pZJGQUaQDjg6k=; h=From:To:Date:Message-Id:MIME-Version; b=DIah/5BL95KO7EQ+KnlGq52KaH5Oryn67xMQ0tGjLpQcBc5A9yMpRyZKO/DMuID2a SDAd/hhEc/CJ84vH7GOMOuCBgtZAmXrqvfKp46rRxCT7lmHK2wTgM/7ITxTVd5S61F DnxWLUQd0LIEizSjxLM0GV1sGwRJ6U0qw0zOZiBLynVPRTyZ0Fpg37EgtVD1qUHL7g 4dr6eDHwuaG4TZysc1nJd9pLaR726PeZtdn1Z0mDblyxaJWCCMDirwwPgkCsxxY3Xy DIcn5Fw96bvOmGYEwBY5/zGNxjyu1JyFSUtcyfitBaZZl8KJpEVu/6K+wXpNrKKfrH Ou4fx0WVsVrFg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id D_a9lrPWSskx; Thu, 9 Jun 2022 14:50:27 -0400 (EDT) Received: from thinkos.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by mail.efficios.com (Postfix) with ESMTPSA id A5BC2412E05; Thu, 9 Jun 2022 14:50:27 -0400 (EDT) From: Mathieu Desnoyers To: grub-devel@gnu.org, Daniel Kiper Cc: Mathieu Desnoyers , Samuel Thibault Subject: [PATCH v5 3/5] grub-mkconfig hurd: Fix quadratic algorithm for sorting menu items Date: Thu, 9 Jun 2022 14:50:22 -0400 Message-Id: <20220609185024.447922-4-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220609185024.447922-1-mathieu.desnoyers@efficios.com> References: <20220609185024.447922-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=167.114.26.124; envelope-from=mathieu.desnoyers@efficios.com; helo=mail.efficios.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jun 2022 18:50:46 -0000 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 Cc: Samuel Thibault --- Changes since v4: - Combine sed -e '...' -e '...' into sed -e '...; ...' --- 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 2fafa4e59..4294bbe4c 100644 --- a/util/grub.d/10_hurd.in +++ b/util/grub.d/10_hurd.in @@ -197,11 +197,17 @@ title_correction_code=3D # 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=3D"" -is_top_level=3Dtrue =20 -while [ "x$kernels" !=3D "x" ] ; do - kernel=3D`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=3D$(echo ${kernels} | tr ' ' '\n' | sed -e 's/\.o= ld$/ 1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$//= ') =20 +is_top_level=3Dtrue + +for kernel in ${reverse_sorted_kernels}; do # The GRUB_DISABLE_SUBMENU option used to be different than others sin= ce 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 opti= on to 'y', @@ -221,8 +227,6 @@ while [ "x$kernels" !=3D "x" ] ; do =20 hurd_entry "$kernel" advanced hurd_entry "$kernel" recovery - - kernels=3D`echo $kernels | tr ' ' '\n' | fgrep -vx "$kernel" | tr '\n'= ' '` done =20 # If at least one kernel was found, then we need to --=20 2.30.2