Skip to content

Restore HashMap performance by allowing some functions to be inlined #25070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl SipHasher {
state
}

#[inline]
fn reset(&mut self) {
self.length = 0;
self.v0 = self.k0 ^ 0x736f6d6570736575;
Expand All @@ -120,6 +121,7 @@ impl SipHasher {
self.ntail = 0;
}

#[inline]
fn write(&mut self, msg: &[u8]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it's unfortunate that this function is so large.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but that's also the most important function to have available for inlining, because most of it is thrown away when the compiler sees that, for example, it's only called with once with a single 8 byte slice. See my remark below about `#[inline(Maybe)].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very true.

let length = msg.len();
self.length += length;
Expand Down Expand Up @@ -173,6 +175,7 @@ impl Hasher for SipHasher {
self.write(msg)
}

#[inline]
fn finish(&self) -> u64 {
let mut v0 = self.v0;
let mut v1 = self.v1;
Expand Down
1 change: 1 addition & 0 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,7 @@ impl 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)
}
Expand Down