Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1ns3la-0008FM-Kv for mharc-grub-devel@gnu.org; Fri, 20 May 2022 10:38:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ns3lR-00086b-Ra for grub-devel@gnu.org; Fri, 20 May 2022 10:38:02 -0400 Received: from mail.efficios.com ([167.114.26.124]:48410) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ns3lO-00066h-Uy for grub-devel@gnu.org; Fri, 20 May 2022 10:38:01 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 25D713EF2C3; Fri, 20 May 2022 10:37:54 -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 b3gc5rN_MQSF; Fri, 20 May 2022 10:37:53 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id BA3F13EF46F; Fri, 20 May 2022 10:37:51 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com BA3F13EF46F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1653057471; bh=5iW6z6oVuJE+VIGGJTMQsuScR51/X4ZyaFyE2J6AzNA=; h=From:To:Date:Message-Id:MIME-Version; b=lkprOEjkoAoeTiFbb8DvPhAtI+r8xzL/vZFs2lyqUMyXC5SNTEgLv3hUOBmpovaCa iHZDRpwIQfwKRchf1gyi9GpXhkQD4Gy6PSwl0kENbtyI7g1JEm2yDi0tWH6b/AruOc iyArjpY40AELvTOt0jLNdFeEZLYzUGHAQGTRCupqLcSYGAoJPPVJJqA6Bpz5jvDDEd MMAzHtS26iuySHAaE7XsjSOh6H3GcWjI5iutykm+vefbuBhb2HL7UV1EF1H9Z8CvKk dE8jK1YZX/eeroCwySDgB2BPR+2YPRteQHqUTsL7zZwYIKqPYUdz9cgEYCXHjlGkSr /b7SbUOcCO5+w== 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 2XF23ZBi0Gaw; Fri, 20 May 2022 10:37:51 -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 8C9683EF150; Fri, 20 May 2022 10:37:50 -0400 (EDT) From: Mathieu Desnoyers To: grub-devel@gnu.org Cc: Mathieu Desnoyers , Samuel Thibault 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 Message-Id: <20220520143741.217690-4-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520143741.217690-1-mathieu.desnoyers@efficios.com> References: <20220520143741.217690-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: Fri, 20 May 2022 14:38:03 -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 --- 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=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/' -e '/ 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/' -e = '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', @@ -219,8 +225,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