@@ -12,12 +12,6 @@ use crate::input::Input;
12
12
/// The global list of eviction functions.
13
13
static EVICTORS : RwLock < Vec < fn ( usize ) > > = RwLock :: new ( Vec :: new ( ) ) ;
14
14
15
- #[ cfg( feature = "testing" ) ]
16
- thread_local ! {
17
- /// Whether the last call was a hit.
18
- static LAST_WAS_HIT : std:: cell:: Cell <bool > = const { std:: cell:: Cell :: new( false ) } ;
19
- }
20
-
21
15
/// Execute a function or use a cached result for it.
22
16
pub fn memoize < ' a , In , Out , F > (
23
17
cache : & Cache < In :: Constraint , Out > ,
37
31
38
32
// Ensure that the last call was a miss during testing.
39
33
#[ cfg( feature = "testing" ) ]
40
- LAST_WAS_HIT . with ( |cell| cell . set ( false ) ) ;
34
+ crate :: testing :: register_miss ( ) ;
41
35
42
36
return output;
43
37
}
59
53
input. retrack ( constraint) . 1 . join ( constrained) ;
60
54
61
55
#[ cfg( feature = "testing" ) ]
62
- LAST_WAS_HIT . with ( |cell| cell . set ( true ) ) ;
56
+ crate :: testing :: register_hit ( ) ;
63
57
64
58
return value. clone ( ) ;
65
59
}
80
74
borrow. insert :: < In > ( key, constraint. take ( ) , output. clone ( ) ) ;
81
75
82
76
#[ cfg( feature = "testing" ) ]
83
- LAST_WAS_HIT . with ( |cell| cell . set ( false ) ) ;
77
+ crate :: testing :: register_miss ( ) ;
84
78
85
79
output
86
80
}
@@ -104,12 +98,6 @@ pub fn register_evictor(evict: fn(usize)) {
104
98
EVICTORS . write ( ) . push ( evict) ;
105
99
}
106
100
107
- /// Whether the last call was a hit.
108
- #[ cfg( feature = "testing" ) ]
109
- pub fn last_was_hit ( ) -> bool {
110
- LAST_WAS_HIT . with ( |cell| cell. get ( ) )
111
- }
112
-
113
101
/// A cache for a single memoized function.
114
102
pub struct Cache < C , Out > ( LazyLock < RwLock < CacheData < C , Out > > > ) ;
115
103
0 commit comments