Skip to content

Commit 796be61

Browse files
committed
Auto merge of #25070 - dotdash:inline_hash, r=alexcrichton
Since the hashmap and its hasher are implemented in different crates, we currently can't benefit from inlining, which means that especially for small, fixed size keys, there is a huge overhead in hash calculations, because the compiler can't apply optimizations that only apply for these keys. Fixes the brainfuck benchmark in #24014.
2 parents 6b3d66b + f4176b5 commit 796be61

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/libcore/hash/sip.rs

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl SipHasher {
111111
state
112112
}
113113

114+
#[inline]
114115
fn reset(&mut self) {
115116
self.length = 0;
116117
self.v0 = self.k0 ^ 0x736f6d6570736575;
@@ -120,6 +121,7 @@ impl SipHasher {
120121
self.ntail = 0;
121122
}
122123

124+
#[inline]
123125
fn write(&mut self, msg: &[u8]) {
124126
let length = msg.len();
125127
self.length += length;
@@ -173,6 +175,7 @@ impl Hasher for SipHasher {
173175
self.write(msg)
174176
}
175177

178+
#[inline]
176179
fn finish(&self) -> u64 {
177180
let mut v0 = self.v0;
178181
let mut v1 = self.v1;

src/libstd/collections/hash/map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,7 @@ impl RandomState {
16001600
reason = "hashing an hash maps may be altered")]
16011601
impl HashState for RandomState {
16021602
type Hasher = SipHasher;
1603+
#[inline]
16031604
fn hasher(&self) -> SipHasher {
16041605
SipHasher::new_with_keys(self.k0, self.k1)
16051606
}

0 commit comments

Comments
 (0)