mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
perf: Canonicalize ignored absolute path only once
This commit is contained in:
+4
-9
@@ -132,19 +132,14 @@ fn is_ignored_path(path: &Path, walk_data: &WalkData) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Entry is inside an ignored absolute path
|
// Entry is inside an ignored absolute path
|
||||||
|
// Absolute paths should be canonicalized before being added to `WalkData.ignore_directories`
|
||||||
for ignored_path in walk_data.ignore_directories.iter() {
|
for ignored_path in walk_data.ignore_directories.iter() {
|
||||||
if !ignored_path.is_absolute() {
|
if !ignored_path.is_absolute() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
match std::fs::canonicalize(ignored_path) {
|
let absolute_entry_path = std::fs::canonicalize(path).unwrap_or_default();
|
||||||
Ok(absolute_ignored_path) => {
|
if absolute_entry_path.starts_with(ignored_path) {
|
||||||
let absolute_entry_path =
|
return true;
|
||||||
std::fs::canonicalize(path).unwrap_or_default();
|
|
||||||
if absolute_entry_path.starts_with(absolute_ignored_path) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => continue,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ use std::sync::atomic::Ordering;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use sysinfo::{System, SystemExt};
|
use sysinfo::{System, SystemExt};
|
||||||
|
use utils::canonicalize_absolute_path;
|
||||||
|
|
||||||
use self::display::draw_it;
|
use self::display::draw_it;
|
||||||
use config::get_config;
|
use config::get_config;
|
||||||
@@ -198,6 +199,7 @@ fn main() {
|
|||||||
Some(values) => values
|
Some(values) => values
|
||||||
.map(|v| v.as_str())
|
.map(|v| v.as_str())
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
|
.map(canonicalize_absolute_path)
|
||||||
.collect::<Vec<PathBuf>>(),
|
.collect::<Vec<PathBuf>>(),
|
||||||
None => vec![],
|
None => vec![],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -67,6 +67,18 @@ pub fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
|
|||||||
path.as_ref().components().collect()
|
path.as_ref().components().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Canonicalize the path only if it is an absolute path
|
||||||
|
pub fn canonicalize_absolute_path(path: PathBuf) -> PathBuf {
|
||||||
|
if path.is_absolute() {
|
||||||
|
match std::fs::canonicalize(&path) {
|
||||||
|
Ok(canonicalized_path) => canonicalized_path,
|
||||||
|
Err(_) => path,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_filtered_out_due_to_regex(filter_regex: &[Regex], dir: &Path) -> bool {
|
pub fn is_filtered_out_due_to_regex(filter_regex: &[Regex], dir: &Path) -> bool {
|
||||||
if filter_regex.is_empty() {
|
if filter_regex.is_empty() {
|
||||||
false
|
false
|
||||||
|
|||||||
Reference in New Issue
Block a user