rustc: Ensure FNV hashing is inlined across crates

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).
This commit is contained in:
Alex Crichton 2016-02-06 22:56:25 -08:00
parent 004c4b4b7d
commit 12a68e6af3

View File

@ -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 {
@ -47,5 +49,7 @@ impl Hasher for FnvHasher {
}
*self = FnvHasher(hash);
}
#[inline]
fn finish(&self) -> u64 { self.0 }
}