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.
This commit is contained in:
@@ -111,6 +111,7 @@ impl SipHasher {
|
|||||||
state
|
state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn reset(&mut self) {
|
fn reset(&mut self) {
|
||||||
self.length = 0;
|
self.length = 0;
|
||||||
self.v0 = self.k0 ^ 0x736f6d6570736575;
|
self.v0 = self.k0 ^ 0x736f6d6570736575;
|
||||||
@@ -120,6 +121,7 @@ impl SipHasher {
|
|||||||
self.ntail = 0;
|
self.ntail = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn write(&mut self, msg: &[u8]) {
|
fn write(&mut self, msg: &[u8]) {
|
||||||
let length = msg.len();
|
let length = msg.len();
|
||||||
self.length += length;
|
self.length += length;
|
||||||
@@ -173,6 +175,7 @@ impl Hasher for SipHasher {
|
|||||||
self.write(msg)
|
self.write(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn finish(&self) -> u64 {
|
fn finish(&self) -> u64 {
|
||||||
let mut v0 = self.v0;
|
let mut v0 = self.v0;
|
||||||
let mut v1 = self.v1;
|
let mut v1 = self.v1;
|
||||||
|
|||||||
@@ -1600,6 +1600,7 @@ impl RandomState {
|
|||||||
reason = "hashing an hash maps may be altered")]
|
reason = "hashing an hash maps may be altered")]
|
||||||
impl HashState for RandomState {
|
impl HashState for RandomState {
|
||||||
type Hasher = SipHasher;
|
type Hasher = SipHasher;
|
||||||
|
#[inline]
|
||||||
fn hasher(&self) -> SipHasher {
|
fn hasher(&self) -> SipHasher {
|
||||||
SipHasher::new_with_keys(self.k0, self.k1)
|
SipHasher::new_with_keys(self.k0, self.k1)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user