mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-21 00:26:13 +08:00
readdir_for_dirs: Actually filter out non-dirs
This function is supposed to return "the next directory". Because this is imperfect, it only tries to. Except it went to all the trouble of figuring out the type and then just... returned it anyway. This has nice speedups in globs with directory components like `*/` or `**`. I have observed 1.1x to 2.0x. We could also return when we know it's definitely a directory and then skip a stat() later, but preliminary testing seemed to show that's not worth much.
This commit is contained in:
parent
dbb4e05254
commit
526b7e3b1b
|
@ -96,6 +96,10 @@ bool wreaddir(DIR *dir, wcstring &out_name) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/// Wrapper for readdir that tries to only return directories.
|
||||
/// This is only supported on some (file)systems,
|
||||
/// and includes links,
|
||||
/// so the caller still needs to check.
|
||||
bool readdir_for_dirs(DIR *dir, std::string *out_name) {
|
||||
struct dirent *result = nullptr;
|
||||
while (!result) {
|
||||
|
@ -110,7 +114,9 @@ bool readdir_for_dirs(DIR *dir, std::string *out_name) {
|
|||
break; // these may be directories
|
||||
}
|
||||
default: {
|
||||
break; // nothing else can
|
||||
// these definitely aren't - skip
|
||||
result = nullptr;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
|
Loading…
Reference in New Issue
Block a user