Skip to content
Myr

Reduce number of 'stat' syscalls from 3 to 1, see #36

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by sharkdp · parent d8c588d · Browse files · 1 file+8 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−7 removed

  • other:+8 added−7 removed

1 file+8 added−7 removed

modified:src/main.rs+8 added-7 removed
116 unmodified lines
117118 let path_str = entry.to_string_lossy();119120 #[cfg(target_family = "unix")]121 let is_executable = |p: &std::path::PathBuf| {122 p.metadata()123 .ok()124 .map(|f| f.permissions().mode() & 0o111 != 0)121 let is_executable = |p: Option<&std::fs::Metadata>| {122 p.map(|f| f.permissions().mode() & 0o111 != 0)123 .unwrap_or(false)124 };125126 #[cfg(not(target_family = "unix"))]
20 unmodified lines
147 };148149 component_path.push(Path::new(comp_str.deref()));150151 let metadata = component_path.metadata().ok();152 let is_directory = metadata.as_ref().map(|md| md.is_dir()).unwrap_or(false);153154 let style =155 if component_path.symlink_metadata()156 .map(|md| md.file_type().is_symlink())157 .unwrap_or(false) {158 &ls_colors.symlink158 } else if component_path.is_dir() {159 } else if is_directory {160 &ls_colors.directory160 } else if is_executable(&component_path) {161 } else if is_executable(metadata.as_ref()) {162 &ls_colors.executable163 } else {164 // Look up file name165 let o_style =
13 unmodified lines
179 };180181 write!(handle, "{}", style.paint(comp_str)).ok();182182 if component_path.is_dir() && component_path != path_full {183 if is_directory && component_path != path_full {184 let sep = std::path::MAIN_SEPARATOR.to_string();185 write!(handle, "{}", style.paint(sep)).ok();186 }187 }
318 unmodified lines