Skip to content

Commit f4176b5

Browse files
committed
Restore HashMap performance by allowing some functions to be inlined
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.
1 parent 0d7d3ec commit f4176b5

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/libcore/hash/sip.rs

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)