mirror of
https://github.com/sharkdp/fd.git
synced 2024-09-29 21:41:30 +02:00
Minor speedup for strip_prefix
This commit is contained in:
parent
82eeeda504
commit
e5ee5eb7b3
@ -20,8 +20,22 @@ use std::os::unix::fs::PermissionsExt;
|
|||||||
|
|
||||||
use ansi_term;
|
use ansi_term;
|
||||||
|
|
||||||
|
/// Remove the `./` prefix from a path.
|
||||||
|
fn strip_current_dir<'a>(pathbuf: &'a PathBuf) -> &'a Path {
|
||||||
|
let mut iter = pathbuf.components();
|
||||||
|
let mut iter_next = iter.clone();
|
||||||
|
if iter_next.next() == Some(Component::CurDir) {
|
||||||
|
iter.next();
|
||||||
|
}
|
||||||
|
iter.as_path()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn print_entry(entry: &PathBuf, config: &FdOptions, wants_to_quit: &Arc<AtomicBool>) {
|
pub fn print_entry(entry: &PathBuf, config: &FdOptions, wants_to_quit: &Arc<AtomicBool>) {
|
||||||
let path = entry.strip_prefix(".").unwrap_or(entry);
|
let path = if entry.is_absolute() {
|
||||||
|
entry.as_path()
|
||||||
|
} else {
|
||||||
|
strip_current_dir(entry)
|
||||||
|
};
|
||||||
|
|
||||||
let r = if let Some(ref ls_colors) = config.ls_colors {
|
let r = if let Some(ref ls_colors) = config.ls_colors {
|
||||||
print_entry_colorized(path, config, ls_colors, &wants_to_quit)
|
print_entry_colorized(path, config, ls_colors, &wants_to_quit)
|
||||||
|
Loading…
Reference in New Issue
Block a user