Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1ns3lZ-0008CF-Ar for mharc-grub-devel@gnu.org; Fri, 20 May 2022 10:38:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ns3lT-000878-5d for grub-devel@gnu.org; Fri, 20 May 2022 10:38:03 -0400 Received: from mail.efficios.com ([167.114.26.124]:48460) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ns3lR-00067C-HH for grub-devel@gnu.org; Fri, 20 May 2022 10:38:02 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 5D9433EF1FF; 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 EqWH1xgirnRf; Fri, 20 May 2022 10:37:54 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id C6B0B3EF506; Fri, 20 May 2022 10:37:51 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com C6B0B3EF506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1653057471; bh=3r9a1BrIFVxpGAPggnKAMzLJ6z5kGqTmWvVbvX4a+fs=; h=From:To:Date:Message-Id:MIME-Version; b=NkRHZcPuWuDzrvsymlmmAIFoVR8INXzdqTGkOq++LVaBcBHFSV52jl/2P0EHK9ekK YHEeT5I1kYLq9vV1paqSO3F8p/ibK16Rvf5VclNTTXnB8XsMtY1Q9ym18C1s3zoXrh PNEOhqBcTIRJdy6CThwhuUmX0iIyS7eZTFCbViRIw1x8e+yizwJkETzr6Ut84gRhcE O1G/LXHULRQDlWVIKeldz5+ZMxm3PfEkX4Z2uS81bnMCcLtbJfrhzJshDNx3Pk2Jbp PbLtsFkCdydmzeYAPHtGFFKeydJzHJq38xzlZpG1ioQBI9B5JR4dV+auI2oiXbnxe+ vTl5KJMuZ0IMA== 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 mAW85PIIJ-x6; 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 A67D83EF58C; Fri, 20 May 2022 10:37:50 -0400 (EDT) From: Mathieu Desnoyers To: grub-devel@gnu.org Cc: Mathieu Desnoyers , debian-bsd@lists.debian.org Subject: [RFC PATCH v3 4/5] grub-mkconfig kfreebsd: Fix quadratic algorithm for sorting menu items Date: Fri, 20 May 2022 10:37:40 -0400 Message-Id: <20220520143741.217690-5-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:04 -0000 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 Cc: debian-bsd@lists.debian.org --- 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..930d8df9c 100644 --- a/util/grub.d/10_kfreebsd.in +++ b/util/grub.d/10_kfreebsd.in @@ -157,10 +157,16 @@ title_correction_code=3D # yet, so it's empty. In a submenu it will be equal to '\t' (one tab). submenu_indentation=3D"" =20 +# 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=3D$(echo ${list} | 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=3Dtrue =20 -while [ "x$list" !=3D "x" ] ; do - kfreebsd=3D`version_find_latest $list` +for kfreebsd in ${reverse_sorted_list}; do gettext_printf "Found kernel of FreeBSD: %s\n" "$kfreebsd" >&2 basename=3D`basename $kfreebsd` dirname=3D`dirname $kfreebsd` @@ -238,8 +244,6 @@ while [ "x$list" !=3D "x" ] ; do if [ "x${GRUB_DISABLE_RECOVERY}" !=3D "xtrue" ]; then kfreebsd_entry "${OS}" "${version}" recovery "-s" fi - - list=3D`echo $list | tr ' ' '\n' | fgrep -vx "$kfreebsd" | tr '\n' ' '= ` done =20 # If at least one kernel was found, then we need to --=20 2.30.2