[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width
From: |
Carl Edquist |
Subject: |
Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width |
Date: |
Thu, 15 Apr 2021 08:33:35 -0500 (CDT) |
On Sat, 10 Apr 2021, P@draigBrady.com wrote:
> I've attached two patches ...
>
> The first adjusts your patch to:
> ...
> Expand in texinfo that --sort=width is most useful with -C (the default)
FWIW i run 'ls -lW' often enough also, to refresh myself of the details of
the files with pesky long names that i might want to do something about.
> The second is a performance improvement,
> as we're now calling quote_name_width a lot more.
Cool!
Yeah in theory i felt bad about the performance overhead, but in practice
it took a directory with on the order of 10k entries before the runtime of
'ls -W >/dev/null' would even be visible to the human eye, after hitting
the enter key. Which seemed reasonable for most interactive purposes.
And if you are actually writing to the terminal in such cases, the runtime
is completely dominated by the terminal rendering.
Still, the version with caching is definitely more efficient, so that is
great.
PS if you are willing to cheat a bit and treat the f->width member as
"mutable" (modifying it even when f is pointer to const), you could
simplify things a bit if you just store the value from quote_name_width()
in fileinfo_name_width(). Something like [1].
Then you can completely drop the new update_current_files_info function,
and get the caching automatically whenever width needs to be calculated.
(And i see your point about avoiding saving the value in the case of
'--format=commas', to maximize hardware caching - but as far as i could
tell, even with 100k directory entries, there was no measurable cpu
performance hit with --format=commas between the current version with
update_current_files_info(), and the version that always saves f->width
when it is calculated.)
Anyway, fun times! :)
Carl
[1]
--- a/src/ls.c
+++ b/src/ls.c
@@ -3892,9 +3892,12 @@ cmp_extension (struct fileinfo const *a, struct fileinfo
const *b,
static inline size_t
fileinfo_name_width (struct fileinfo const *f)
{
- return f->width
- ? f->width
- : quote_name_width (f->name, filename_quoting_options, f->quoted);
+ if (!f->width)
+ {
+ ((struct fileinfo *) f)->width =
+ quote_name_width (f->name, filename_quoting_options, f->quoted);
+ }
+ return f->width;
}
static inline int
- Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width, (continued)
- Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width, Carl Edquist, 2021/04/15
- Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width, Michael Stone, 2021/04/15
- Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width, Carl Edquist, 2021/04/15
- Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width, Tony Freeman, 2021/04/15
- Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width, Glenn Golden, 2021/04/15
- Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width, Pádraig Brady, 2021/04/17
- Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width,
Carl Edquist <=
- Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width, Pádraig Brady, 2021/04/15
- Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width, Carl Edquist, 2021/04/15
Re: [PATCH] ls: add --sort=width (-W) option to sort by filename width, Kaz Kylheku (Coreutils), 2021/04/16