Skip to content

Commit

Permalink
rustc: Ensure FNV hashing is inlined across crates
Browse files Browse the repository at this point in the history
Right now the primary hashing algorithm of the compiler isn't actually inlined
across crates, meaning that it may be missing out on some crucial optimizations
in a few places (perhaps unrolling smaller loops, etc).

This commit made the hashing function disappear from a profiled version of the
compiler, but that's likely because it was just inlined elsewhere. When
compiling winapi, however, this decreased compile time from 18.3 to 17.8 seconds
(a 3% improvement).
  • Loading branch information
alexcrichton committed Feb 14, 2016
1 parent 004c4b4 commit 12a68e6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/librustc_data_structures/fnv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ pub fn FnvHashSet<V: Hash + Eq>() -> FnvHashSet<V> {
pub struct FnvHasher(u64);

impl Default for FnvHasher {
#[inline]
fn default() -> FnvHasher { FnvHasher(0xcbf29ce484222325) }
}

impl Hasher for FnvHasher {
#[inline]
fn write(&mut self, bytes: &[u8]) {
let FnvHasher(mut hash) = *self;
for byte in bytes {
Expand All @@ -47,5 +49,7 @@ impl Hasher for FnvHasher {
}
*self = FnvHasher(hash);
}

#[inline]
fn finish(&self) -> u64 { self.0 }
}

0 comments on commit 12a68e6

Please sign in to comment.