Skip to content

Commit 1f284b0

Browse files
committed
Add special case for length 1
1 parent ac08f13 commit 1f284b0

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

compiler/rustc_data_structures/src/stable_hasher.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -559,20 +559,28 @@ where
559559
fn stable_hash_reduce<HCX, I, C, F>(
560560
hcx: &mut HCX,
561561
hasher: &mut StableHasher,
562-
collection: C,
562+
mut collection: C,
563563
length: usize,
564564
hash_function: F,
565565
) where
566566
C: Iterator<Item = I>,
567567
F: Fn(&mut StableHasher, &mut HCX, I),
568568
{
569-
let hash = collection
570-
.map(|value| {
571-
let mut hasher = StableHasher::new();
572-
hash_function(&mut hasher, hcx, value);
573-
hasher.finish::<u128>()
574-
})
575-
.reduce(|accum, value| accum.wrapping_add(value));
576569
length.hash_stable(hcx, hasher);
577-
hash.hash_stable(hcx, hasher);
570+
571+
match length {
572+
1 => {
573+
hash_function(hasher, hcx, collection.next().unwrap());
574+
}
575+
_ => {
576+
let hash = collection
577+
.map(|value| {
578+
let mut hasher = StableHasher::new();
579+
hash_function(&mut hasher, hcx, value);
580+
hasher.finish::<u128>()
581+
})
582+
.reduce(|accum, value| accum.wrapping_add(value));
583+
hash.hash_stable(hcx, hasher);
584+
}
585+
}
578586
}

0 commit comments

Comments
 (0)