Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1o0kk6-0008A5-LU for mharc-grub-devel@gnu.org; Mon, 13 Jun 2022 10:08:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0kk1-00083X-EM for grub-devel@gnu.org; Mon, 13 Jun 2022 10:08:29 -0400 Received: from mail.efficios.com ([167.114.26.124]:34676) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0kjz-0003Vg-Dw for grub-devel@gnu.org; Mon, 13 Jun 2022 10:08:29 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id EA7703B1BE9; Mon, 13 Jun 2022 10:08:26 -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 V3s-iCkYQFHI; Mon, 13 Jun 2022 10:08:26 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 54F163B1BCF; Mon, 13 Jun 2022 10:08:24 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 54F163B1BCF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1655129304; bh=5/oQZ3XChVYNR/+wnYml7D8P8IwC85S6MuitJfInikQ=; h=From:To:Date:Message-Id:MIME-Version; b=XuuA0oIPwUaa9gonT3N5d8cTAeOQYX2lEqcvLwXPnn/bqD8HDRLzLgRMa3QAdFPLv oVpKKEEeEl4gF7zWQUCkO8KJlFGN4nYnGC0iPuuft/zbLc0lhd4+KKFBUvhS7qN9hp OiQy4hDNa00TfQa0Y0Q9cyqb/s6nMlMHG9rusTnD9j7PLxcKLrlQqah4Qh7OPI2ov/ LohgHd4LNP6W17WW51x//nsrQZD30SW42yBnrpDYobLf9WlQ1Qh6dsZi+4T62jV7Xd ZICf9qU+6Lrcf41qFyOqYg27ITHIgV5mD06I9a34WdR6XycVi7gVIJIAfPR8gVo0ML 2ySFO0GLK4cgw== 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 r4JSGsWhRbl7; Mon, 13 Jun 2022 10:08:24 -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 D94D63B1BB9; Mon, 13 Jun 2022 10:08:21 -0400 (EDT) From: Mathieu Desnoyers To: grub-devel@gnu.org, Daniel Kiper Cc: Mathieu Desnoyers , debian-bsd@lists.debian.org Subject: [PATCH v6 4/5] grub-mkconfig kfreebsd: Fix quadratic algorithm for sorting menu items Date: Mon, 13 Jun 2022 10:08:25 -0400 Message-Id: <20220613140826.571036-5-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220613140826.571036-1-mathieu.desnoyers@efficios.com> References: <20220613140826.571036-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: Mon, 13 Jun 2022 14:08:29 -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 --- 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=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= /; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; 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