Skip to content
Myr

Minor speedup for strip_prefix

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

authored by sharkdp · committed by David Peter · parent 82eeeda · Browse files · 1 file+15 added−1 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+15 added−1 removed

  • other:+15 added−1 removed

1 file+15 added−1 removed

modified:src/output.rs+15 added-1 removed
18 unmodified lines
19use std::os::unix::fs::PermissionsExt;2021use ansi_term;2223/// Remove the `./` prefix from a path.24fn strip_current_dir<'a>(pathbuf: &'a PathBuf) -> &'a Path {25 let mut iter = pathbuf.components();26 let mut iter_next = iter.clone();27 if iter_next.next() == Some(Component::CurDir) {28 iter.next();29 }30 iter.as_path()31}3233pub fn print_entry(entry: &PathBuf, config: &FdOptions, wants_to_quit: &Arc<AtomicBool>) {24 let path = entry.strip_prefix(".").unwrap_or(entry);34 let path = if entry.is_absolute() {35 entry.as_path()36 } else {37 strip_current_dir(entry)38 };3940 let r = if let Some(ref ls_colors) = config.ls_colors {41 print_entry_colorized(path, config, ls_colors, &wants_to_quit)42 } else {
103 unmodified lines