From 1f284b07edaae02324947221b2e0660e07fc5618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Mon, 13 Dec 2021 21:34:54 +0100 Subject: [PATCH] Add special case for length 1 --- .../src/stable_hasher.rs | 26 ++++++++++++------- 1 file 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: &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); + } + } }