]> git.ipfire.org Git - thirdparty/coreutils.git/commit
ls: cache name width determination
authorPádraig Brady <P@draigBrady.com>
Sat, 10 Apr 2021 15:54:03 +0000 (16:54 +0100)
committerPádraig Brady <P@draigBrady.com>
Sun, 11 Apr 2021 13:58:45 +0000 (14:58 +0100)
commit34ed19eed8fe1e29372f19883c846f888fd79f0e
tree98869d14b64851abb4d87c64604140c98b880ea5
parent751ad58e00a7cacfb511f651837d336253eb672c
ls: cache name width determination

This is especially important now for --sort=width,
as that can greatly increase how often this
expensive quote_name_width() function is called per file.

This also helps the default invocation of ls,
or specifically the --format={across,vertical} cases
(when --width is not set to 0),
to avoid two calls to this function per file.

Note the only case where we later compute the width,
is for --format=commas.  That's only done once though,
so we leave the computation close to use to
maximize hardware caching.

* src/ls.c (struct fileinfo): Add a WIDTH member to cache
the screen width of the file name.
(update_current_files_info): Set the WIDTH members for cases
they're needed multiple times.  Note we do this explicitly here,
rather than caching at use, so that the fileinfo
structures can remain const in the sorting and presentation functions.
(sort_files): Call the new update_current_files_info() in this
initialization function.
(fileinfo_name_width): Renamed from fileinfo_width,
and adjusted to return the cached value if available.
src/ls.c