[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2] grub-mkconfig linux: Fix quadratic algorithm for sorting
From: |
Mathieu Desnoyers |
Subject: |
Re: [PATCH v2] grub-mkconfig linux: Fix quadratic algorithm for sorting menu items |
Date: |
Wed, 4 May 2022 11:24:07 -0400 (EDT) |
----- On May 4, 2022, at 10:43 AM, Robbie Harwood rharwood@redhat.com wrote:
> Mathieu Desnoyers <mathieu.desnoyers@efficios.com> writes:
>
>> +version_reverse_sort ()
>> +{
>> + case $version_reverse_sort_sort_has_v in
>
> Does this need to be its own variable, or could it just reuse
> version_sort_sort_has_v?
We could do that, assuming that both sort -r -V and sort -V always work (or
don't)
in the same way.
Then I would change the test in version_reverse_sort to:
if sort -V </dev/null > /dev/null 2>&1; then
There is no point in calling this check with "-r" if it sets
version_sort_sort_has_v.
>
>> +reverse_sorted_list=$(echo $list | tr ' ' '\n' | sed 's/$/ 2/' | sed
>> 's/\.old
>> 2/ 1/' | version_reverse_sort | sed 's/ 1$/.old/' | sed 's/ 2$//')
>
> Could the `sed | sed` pattern be collapsed into a single invocation
> using multiple -e switches?1
I think we can straightforwardly turn "| sed 's/ 1$/.old/' | sed 's/ 2$//'"
into "| sed -e 's/ 1$/.old/' -e 's/ 2$//'".
How to match that all lines ending with ".old" need to be replaced with a
" 1" suffix, and all _other_ lines need to be suffixed with " 2" in a single
sed invocation is unclear to me. Any idea ?
Thanks,
Mathieu
>
> Be well,
> --Robbie
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com