diff options
| author | Jakub Beránek <berykubik@gmail.com> | 2021-12-13 21:34:54 +0100 |
|---|---|---|
| committer | Jakub Beránek <berykubik@gmail.com> | 2021-12-13 21:34:54 +0100 |
| commit | 1f284b07edaae02324947221b2e0660e07fc5618 (patch) | |
| tree | fa82a04f1184cb3188f4b26c4bc2468608bd7451 /compiler/rustc_data_structures/src | |
| parent | ac08f13948303491ed4a00f0578bd64f0327769c (diff) | |
| download | rust-1f284b07edaae02324947221b2e0660e07fc5618.tar.gz rust-1f284b07edaae02324947221b2e0660e07fc5618.zip | |
Add special case for length 1
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/stable_hasher.rs | 26 |
1 files changed, 17 insertions, 9 deletions
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 @@ 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); + } + } } |
