From 806821e6cc9292f817821899253f61d04d61f3f4 Mon Sep 17 00:00:00 2001 From: Jon Moroney Date: Sun, 2 Aug 2020 14:30:34 -0700 Subject: [PATCH] Skip unrapping hashes in comparison Rust will inspect the contents of an option in equality checking Skipping the unwrap step resolves thread panics where a zero length file will have no hash --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6a52695..0151143 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -331,9 +331,9 @@ fn differentiate_and_consolidate(file_length: u64, mut files: Vec) -> }); return dedupe(files) } - let mut partial_hashes: HashMap = HashMap::new(); + let mut partial_hashes: HashMap, u64> = HashMap::new(); for file in files.iter(){ - match partial_hashes.entry(file.get_partial_hash().unwrap()){ + match partial_hashes.entry(file.get_partial_hash()){ Entry::Vacant(e) => { e.insert(0); }, Entry::Occupied(mut e) => {*e.get_mut()+=1;} } @@ -344,7 +344,7 @@ fn differentiate_and_consolidate(file_length: u64, mut files: Vec) -> .map(|y| y.0) .collect(); files.par_iter_mut().for_each(|x| - if dedupe_hashes.contains(&x.get_partial_hash().unwrap()){ + if dedupe_hashes.contains(&x.get_partial_hash()){ let hash = x.generate_hash(HashMode::Full); x.set_full_hash(hash); }