From e61d1f1475d00525bd743e48a9f5ba0b6b698522 Mon Sep 17 00:00:00 2001 From: Valentin Bersier Date: Wed, 18 Jan 2023 08:07:51 +0100 Subject: [PATCH] perf: unwrap the size once --- src/output.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/output.rs b/src/output.rs index 2d635e8..3bd0e8a 100644 --- a/src/output.rs +++ b/src/output.rs @@ -152,7 +152,8 @@ pub fn print(duplicates: DashMap>, opts: &Params) { let size = f.1.first() .and_then(|ff| fs::metadata(&ff.path).ok()) - .and_then(|m| Some(m.len())); + .and_then(|m| Some(m.len())) + .unwrap_or_default(); (f.0, f.1, size) }) .sorted_unstable_by_key(|f| f.2) // sort by ascending size @@ -164,7 +165,7 @@ pub fn print(duplicates: DashMap>, opts: &Params) { format_path(&file.path, opts).unwrap_or_default().blue(), // since all files should logically have the same size, // we can print the pre-computed size of the first element in the group - format!("{:>12}", format_size(size.unwrap_or_default(), DECIMAL)).red(), + format!("{:>12}", format_size(size, DECIMAL)).red(), modified_time(&file.path).unwrap_or_default().yellow() ]); });