Skip to content

Commit 17bcdd2

Browse files
committed
Hash first
1 parent a6de443 commit 17bcdd2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/cache.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ where
109109
Out: Clone + 'static,
110110
F: FnOnce(In::Tracked<'c>) -> Out,
111111
{
112+
// Compute the hash of the input's key part.
113+
let key = {
114+
let mut state = SipHasher13::new();
115+
input.key(&mut state);
116+
state.finish128().as_u128()
117+
};
118+
119+
std::hint::black_box(key);
120+
112121
if let Some(i) = PRESCIENCE_READ.get() {
113122
if i != u32::MAX {
114123
return cache.0.read().values[i as usize].clone();
@@ -128,13 +137,6 @@ where
128137
return value;
129138
}
130139

131-
// Compute the hash of the input's key part.
132-
let key = {
133-
let mut state = SipHasher13::new();
134-
input.key(&mut state);
135-
state.finish128().as_u128()
136-
};
137-
138140
// Check if there is a cached output.
139141
if let Some((i, value, mutable)) = cache.0.read().lookup::<In>(key, &input) {
140142
PRESCIENCE_WRITE.hit(i);

0 commit comments

Comments
 (0)