Use SmallVec in Hash map stable hashing

This commit is contained in:
Jakub Beránek 2021-10-25 08:26:00 +02:00
parent 91b931926f
commit e4b4d18f58
No known key found for this signature in database
GPG Key ID: DBC553E540C2F619

View File

@ -552,7 +552,8 @@ pub fn hash_stable_hashmap<HCX, K, V, R, SK, F>(
SK: HashStable<HCX> + Ord,
F: Fn(&K, &HCX) -> SK,
{
let mut entries: Vec<_> = map.iter().map(|(k, v)| (to_stable_hash_key(k, hcx), v)).collect();
let mut entries: SmallVec<[_; 3]> =
map.iter().map(|(k, v)| (to_stable_hash_key(k, hcx), v)).collect();
entries.sort_unstable_by(|&(ref sk1, _), &(ref sk2, _)| sk1.cmp(sk2));
entries.hash_stable(hcx, hasher);
}