From 641976cf7ad311ba741571ca8b7f02b2654b6955 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Sun, 19 Aug 2018 16:23:06 +0200 Subject: [PATCH] Remove duplicated `lstat` syscall Removes a unnecessary `lstat` syscall by calling `.metadata()` only once. This makes `--type executable` searches about 15% faster. --- src/walk.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/walk.rs b/src/walk.rs index e935c32b0..2f5a144fb 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -219,9 +219,10 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) { if (entry_type.is_file() && !file_types.files) || (entry_type.is_dir() && !file_types.directories) || (entry_type.is_symlink() && !file_types.symlinks) - || (entry.metadata().is_ok() - && !fshelper::is_executable(&entry.metadata().unwrap()) - && file_types.executables_only) + || (file_types.executables_only && !entry + .metadata() + .map(|m| fshelper::is_executable(&m)) + .unwrap_or(false)) { return ignore::WalkState::Continue; } else if !(entry_type.is_file()