Skip to content

Commit

Permalink
Add special case for length 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Dec 13, 2021
1 parent ac08f13 commit 1f284b0
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions compiler/rustc_data_structures/src/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,20 +559,28 @@ where
fn stable_hash_reduce<HCX, I, C, F>(
hcx: &mut HCX,
hasher: &mut StableHasher,
collection: C,
mut collection: C,
length: usize,
hash_function: F,
) where
C: Iterator<Item = I>,
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::<u128>()
})
.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::<u128>()
})
.reduce(|accum, value| accum.wrapping_add(value));
hash.hash_stable(hcx, hasher);
}
}
}

0 comments on commit 1f284b0

Please sign in to comment.