From: Jakub Beránek Date: Mon, 13 Dec 2021 20:34:54 +0000 (+0100) Subject: Add special case for length 1 X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=1f284b07edaae02324947221b2e0660e07fc5618;p=rust.git Add special case for length 1 --- diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index f37cf76c32b..144eaed7e07 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -559,20 +559,28 @@ fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { fn stable_hash_reduce( hcx: &mut HCX, hasher: &mut StableHasher, - collection: C, + mut collection: C, length: usize, hash_function: F, ) where C: Iterator, F: Fn(&mut StableHasher, &mut HCX, I), { - let hash = collection - .map(|value| { - let mut hasher = StableHasher::new(); - hash_function(&mut hasher, hcx, value); - hasher.finish::() - }) - .reduce(|accum, value| accum.wrapping_add(value)); length.hash_stable(hcx, hasher); - hash.hash_stable(hcx, hasher); + + match length { + 1 => { + hash_function(hasher, hcx, collection.next().unwrap()); + } + _ => { + let hash = collection + .map(|value| { + let mut hasher = StableHasher::new(); + hash_function(&mut hasher, hcx, value); + hasher.finish::() + }) + .reduce(|accum, value| accum.wrapping_add(value)); + hash.hash_stable(hcx, hasher); + } + } }