Skip to content

Commit

Permalink
Fix StarlarkHasher
Browse files Browse the repository at this point in the history
Summary:
Default implementation of `FxHasher64` for function like `write64` converts `u64` to bytes, and then extracts `u64` from bytes. This conversion is mostly optimized away, but not perfectly, I think.

This change omits this step of converting to bytes.

Reviewed By: JakobDegen

Differential Revision: D54317681

fbshipit-source-id: 15fcd739075a23de4d922f1c610797ce79fbe5dd
  • Loading branch information
stepancheg authored and facebook-github-bot committed Feb 28, 2024
1 parent a94e951 commit ac2d3f7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions starlark_map/src/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@ impl Hasher for StarlarkHasher {
fn write(&mut self, bytes: &[u8]) {
self.0.write(bytes)
}

#[inline]
fn write_u8(&mut self, i: u8) {
self.0.write_u8(i)
}

#[inline]
fn write_u16(&mut self, i: u16) {
self.0.write_u16(i)
}

#[inline]
fn write_u32(&mut self, i: u32) {
self.0.write_u32(i)
}

#[inline]
fn write_u64(&mut self, i: u64) {
self.0.write_u64(i)
}

#[inline]
fn write_u128(&mut self, i: u128) {
self.0.write_u128(i)
}

#[inline]
fn write_usize(&mut self, i: usize) {
self.0.write_usize(i)
}
}

/// [`BuildHasher`] implementation which produces [`StarlarkHasher`].
Expand Down

0 comments on commit ac2d3f7

Please sign in to comment.