perf: unwrap the size once

This commit is contained in:
Valentin Bersier
2023-01-18 08:07:51 +01:00
parent 8c76c6a3c8
commit e61d1f1475

View File

@@ -152,7 +152,8 @@ pub fn print(duplicates: DashMap<String, Vec<File>>, 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<String, Vec<File>>, 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()
]);
});