wildcard: Remove useless access() call for trailing slash

This confirmed that a file existed via access(file, F_OK).

But we already *know* that it does because this is the expansion for
the "trailing slash" - by definition all wildcard components up to
here have already been checked.

And it's not checking for directoryness either because it does F_OK.

This will remove one `access()` per result, which will cut the number
of syscalls needed for a glob that ends in a "/" in half.

This brings us on-par with e.g. `ls` (which uses statx while we use
newfstatat, but that should have about the same results)

Fixes #9891.
This commit is contained in:
Fabian Boehm 2023-07-14 20:17:19 +02:00
parent 861da91bf1
commit 6823f5e337

View file

@ -679,11 +679,8 @@ void wildcard_expander_t::expand_trailing_slash(const wcstring &base_dir, const
} }
if (!(flags & expand_flag::for_completions)) { if (!(flags & expand_flag::for_completions)) {
// Trailing slash and not accepting incomplete, e.g. `echo /xyz/`. Insert this file if it // Trailing slash and not accepting incomplete, e.g. `echo /xyz/`. Insert this file, we already know it exists!
// exists. this->add_expansion_result(wcstring{base_dir});
if (waccess(base_dir, F_OK) == 0) {
this->add_expansion_result(wcstring{base_dir});
}
} else { } else {
// Trailing slashes and accepting incomplete, e.g. `echo /xyz/<tab>`. Everything is added. // Trailing slashes and accepting incomplete, e.g. `echo /xyz/<tab>`. Everything is added.
dir_iter_t dir = open_dir(base_dir); dir_iter_t dir = open_dir(base_dir);