diff options
author | andy.boot <bootandy@gmail.com> | 2024-07-17 00:24:32 +0100 |
---|---|---|
committer | andy.boot <bootandy@gmail.com> | 2024-07-17 00:27:29 +0100 |
commit | e5da9cd8440e5c0ffa2a1881ac5449552597b9be (patch) | |
tree | 52397d54e817f6b8879c917eee4fc456942e9a52 | |
parent | b4a517a09648a72a4e0752bc2927204fc961cba6 (diff) |
fix: perf issues with v1.1.0i_wanna_go_fast
Bring performance back
-rw-r--r-- | src/config.rs | 16 | ||||
-rw-r--r-- | src/dir_walker.rs | 52 | ||||
-rw-r--r-- | src/utils.rs | 12 |
3 files changed, 45 insertions, 35 deletions
diff --git a/src/config.rs b/src/config.rs index 71f3890..dceb783 100644 --- a/src/config.rs +++ b/src/config.rs @@ -145,21 +145,21 @@ impl Config { Some(true) == self.output_json || options.get_flag("output_json") } - pub fn get_modified_time_operator(&self, options: &ArgMatches) -> (Operater, i64) { + pub fn get_modified_time_operator(&self, options: &ArgMatches) -> Option<(Operater, i64)> { get_filter_time_operator( options.get_one::<String>("mtime"), get_current_date_epoch_seconds(), ) } - pub fn get_accessed_time_operator(&self, options: &ArgMatches) -> (Operater, i64) { + pub fn get_accessed_time_operator(&self, options: &ArgMatches) -> Option<(Operater, i64)> { get_filter_time_operator( options.get_one::<String>("atime"), get_current_date_epoch_seconds(), ) } - pub fn get_created_time_operator(&self, options: &ArgMatches) -> (Operater, i64) { + pub fn get_created_time_operator(&self, options: &ArgMatches) -> Option<(Operater, i64)> { get_filter_time_operator( options.get_one::<String>("ctime"), get_current_date_epoch_seconds(), @@ -182,7 +182,7 @@ fn get_current_date_epoch_seconds() -> i64 { fn get_filter_time_operator( option_value: Option<&String>, current_date_epoch_seconds: i64, -) -> (Operater, i64) { +) -> Option<(Operater, i64)> { match option_value { Some(val) => { let time = current_date_epoch_seconds @@ -192,12 +192,12 @@ fn get_filter_time_operator( .abs() * DAY_SECONDS; match val.chars().next().expect("Value should not be empty") { - '+' => (Operater::LessThan, time - DAY_SECONDS), - '-' => (Operater::GreaterThan, time), - _ => (Operater::Equal, time - DAY_SECONDS), + '+' => Some((Operater::LessThan, time - DAY_SECONDS)), + '-' => Some((Operater::GreaterThan, time)), + _ => Some((Operater::Equal, time - DAY_SECONDS)), } } - None => (Operater::GreaterThan, 0), + None => None, } } diff --git a/src/dir_walker.rs b/src/dir_walker.rs index cfd016e..f483639 100644 --- a/src/dir_walker.rs +++ b/src/dir_walker.rs @@ -35,9 +35,9 @@ pub struct WalkData<'a> { pub filter_regex: &'a [Regex], pub invert_filter_regex: &'a [Regex], pub allowed_filesystems: HashSet<u64>, - pub filter_modified_time: (Operater, i64), - pub filter_accessed_time: (Operater, i64), - pub filter_changed_time: (Operater, i64), + pub filter_modified_time: Option<(Operater, i64)>, + pub filter_accessed_time: Option<(Operater, i64)>, + pub filter_changed_time: Option<(Operater, i64)>, pub use_apparent_size: bool, pub by_filecount: bool, pub ignore_hidden: bool, @@ -116,27 +116,33 @@ fn ignore_file(entry: &DirEntry, walk_data: &WalkData) -> bool { let is_dot_file = entry.file_name().to_str().unwrap_or("").starts_with('.'); let is_ignored_path = walk_data.ignore_directories.contains(&entry.path()); - let size_inode_device = get_metadata(entry.path(), false); - if let Some((_size, Some((_id, dev)), (modified_time, accessed_time, changed_time))) = - size_inode_device - { - if !walk_data.allowed_filesystems.is_empty() - && !walk_data.allowed_filesystems.contains(&dev) - { - return true; + if !walk_data.allowed_filesystems.is_empty() { + let size_inode_device = get_metadata(entry.path(), false); + if let Some((_size, Some((_id, dev)), _gunk)) = size_inode_device { + if !walk_data.allowed_filesystems.contains(&dev) { + return true; + } } - if entry.path().is_file() - && [ - (&walk_data.filter_modified_time, modified_time), - (&walk_data.filter_accessed_time, accessed_time), - (&walk_data.filter_changed_time, changed_time), - ] - .iter() - .any(|(filter_time, actual_time)| { - is_filtered_out_due_to_file_time(filter_time, *actual_time) - }) - { - return true; + } + if walk_data.filter_accessed_time.is_some() + || walk_data.filter_modified_time.is_some() + || walk_data.filter_changed_time.is_some() + { + let size_inode_device = get_metadata(entry.path(), false); + if let Some((_, _, (modified_time, accessed_time, changed_time))) = size_inode_device { + if entry.path().is_file() + && [ + (&walk_data.filter_modified_time, modified_time), + (&walk_data.filter_accessed_time, accessed_time), + (&walk_data.filter_changed_time, changed_time), + ] + .iter() + .any(|(filter_time, actual_time)| { + is_filtered_out_due_to_file_time(filter_time, *actual_time) + }) + { + return true; + } } } diff --git a/src/utils.rs b/src/utils.rs index 5e66720..9be611c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -65,13 +65,17 @@ pub fn is_filtered_out_due_to_regex(filter_regex: &[Regex], dir: &Path) -> bool } } -pub fn is_filtered_out_due_to_file_time(filter_time: &(Operater, i64), actual_time: i64) -> bool { +pub fn is_filtered_out_due_to_file_time( + filter_time: &Option<(Operater, i64)>, + actual_time: i64, +) -> bool { match filter_time { - (Operater::Equal, bound_time) => { + None => false, + Some((Operater::Equal, bound_time)) => { !(actual_time >= *bound_time && actual_time < *bound_time + DAY_SECONDS) } - (Operater::GreaterThan, bound_time) => actual_time < *bound_time, - (Operater::LessThan, bound_time) => actual_time > *bound_time, + Some((Operater::GreaterThan, bound_time)) => actual_time < *bound_time, + Some((Operater::LessThan, bound_time)) => actual_time > *bound_time, } } |