]> git.lizzy.rs Git - rust.git/commitdiff
Restore HashMap performance by allowing some functions to be inlined
authorBjörn Steinbrink <bsteinbr@gmail.com>
Sun, 3 May 2015 12:02:25 +0000 (14:02 +0200)
committerBjörn Steinbrink <bsteinbr@gmail.com>
Sun, 3 May 2015 12:08:30 +0000 (14:08 +0200)
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.

src/libcore/hash/sip.rs
src/libstd/collections/hash/map.rs

index be419e2cdadb0ed9c33a86eb708c6d513063f029..a92b72e0f00faa542598e1ccd7650277c9526902 100644 (file)
@@ -111,6 +111,7 @@ pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher {
         state
     }
 
+    #[inline]
     fn reset(&mut self) {
         self.length = 0;
         self.v0 = self.k0 ^ 0x736f6d6570736575;
@@ -120,6 +121,7 @@ fn reset(&mut self) {
         self.ntail = 0;
     }
 
+    #[inline]
     fn write(&mut self, msg: &[u8]) {
         let length = msg.len();
         self.length += length;
@@ -173,6 +175,7 @@ fn write(&mut self, msg: &[u8]) {
         self.write(msg)
     }
 
+    #[inline]
     fn finish(&self) -> u64 {
         let mut v0 = self.v0;
         let mut v1 = self.v1;
index ec130e8233a74ac51d55304f43ee7e81a7a03a30..f82c1653be1ae5697ed6c7f4a58395abae112553 100644 (file)
@@ -1600,6 +1600,7 @@ pub fn new() -> RandomState {
            reason = "hashing an hash maps may be altered")]
 impl HashState for RandomState {
     type Hasher = SipHasher;
+    #[inline]
     fn hasher(&self) -> SipHasher {
         SipHasher::new_with_keys(self.k0, self.k1)
     }