From 3cd5c95ab0618924d790fcd19f31883e020cc90f Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 23 Oct 2021 12:11:05 -0400 Subject: [PATCH] Specialize HashStable for [u8] slices Particularly for ctfe-stress-4, the hashing of byte slices as part of the MIR Allocation is quite hot. Previously, we were falling back on byte-by-byte copying of the slice into the SipHash buffer (64 bytes long) before hashing a 64 byte chunk, and then doing that again and again. This should hopefully be an improvement for that code. --- compiler/rustc_data_structures/src/stable_hasher.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index 354f9dd93cc4d..f800ec6a6a12c 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -301,6 +301,13 @@ impl, CTX> HashStable for [T] { } } +impl HashStable for [u8] { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + self.len().hash_stable(ctx, hasher); + hasher.write(self); + } +} + impl, CTX> HashStable for Vec { #[inline] fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {