Skip to content

Commit bdcb528

Browse files
committed
Auto merge of #90208 - Mark-Simulacrum:hash-bytes-fast, r=oli-obk
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; now we use the dedicated byte-slice write.
2 parents a99c9d6 + 3cd5c95 commit bdcb528

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compiler/rustc_data_structures/src/stable_hasher.rs

+7
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ impl<T: HashStable<CTX>, CTX> HashStable<CTX> for [T] {
301301
}
302302
}
303303

304+
impl<CTX> HashStable<CTX> for [u8] {
305+
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
306+
self.len().hash_stable(ctx, hasher);
307+
hasher.write(self);
308+
}
309+
}
310+
304311
impl<T: HashStable<CTX>, CTX> HashStable<CTX> for Vec<T> {
305312
#[inline]
306313
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {

0 commit comments

Comments
 (0)