Skip to content

Commit 3272634

Browse files
authored
Simplify disabled memoization code path (#14)
1 parent 20b1c20 commit 3272634

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

src/cache.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ where
3232
F: FnOnce(In) -> Out,
3333
{
3434
// Early bypass if memoization is disabled.
35-
// Hopefully the compiler will optimize this away, if the condition is constant.
3635
if !enabled {
37-
return memoized_disabled(input, constraint, func);
36+
let output = func(input);
37+
38+
// Ensure that the last call was a miss during testing.
39+
#[cfg(feature = "testing")]
40+
LAST_WAS_HIT.with(|cell| cell.set(false));
41+
42+
return output;
3843
}
3944

4045
// Compute the hash of the input's key part.
@@ -80,30 +85,6 @@ where
8085
output
8186
}
8287

83-
fn memoized_disabled<'a, In, Out, F>(
84-
input: In,
85-
constraint: &'a In::Constraint,
86-
func: F,
87-
) -> Out
88-
where
89-
In: Input<'a>,
90-
Out: Clone + 'static,
91-
F: FnOnce(In) -> Out,
92-
{
93-
// Execute the function with the new constraints hooked in.
94-
let (input, outer) = input.retrack(constraint);
95-
let output = func(input);
96-
97-
// Add the new constraints to the outer ones.
98-
outer.join(constraint);
99-
100-
// Ensure that the last call was a miss during testing.
101-
#[cfg(feature = "testing")]
102-
LAST_WAS_HIT.with(|cell| cell.set(false));
103-
104-
output
105-
}
106-
10788
/// Evict the global cache.
10889
///
10990
/// This removes all memoized results from the cache whose age is larger than or

0 commit comments

Comments
 (0)