@@ -29,21 +29,20 @@ impl<I> CachedOnDiskCorpus<I>
29
29
where
30
30
I : Input ,
31
31
{
32
- fn cache_testcase < ' a > (
33
- & ' a self ,
34
- testcase : & ' a RefCell < Testcase < I > > ,
35
- id : CorpusId ,
36
- ) -> Result < ( ) , Error > {
37
- if testcase. borrow ( ) . input ( ) . is_none ( ) {
38
- self . load_input_into ( & mut testcase. borrow_mut ( ) ) ?;
32
+ fn cache_testcase_input < ' a > ( & ' a self , testcase : & ' a mut Testcase < I > ) -> Result < ( ) , Error > {
33
+ let id = testcase
34
+ . corpus_id ( )
35
+ . ok_or ( Error :: unknown ( "The testcase is not associated with an id" ) ) ?;
36
+ if testcase. input ( ) . is_none ( ) {
37
+ self . inner . load_input_into ( testcase) ?;
39
38
let mut borrowed_num = 0 ;
40
39
while self . cached_indexes . borrow ( ) . len ( ) >= self . cache_max_len {
41
- let removed = self . cached_indexes . borrow_mut ( ) . pop_front ( ) . unwrap ( ) ;
40
+ let to_be_evicted = self . cached_indexes . borrow_mut ( ) . pop_front ( ) . unwrap ( ) ;
42
41
43
- if let Ok ( mut borrowed) = self . inner . get_from_all ( removed ) ?. try_borrow_mut ( ) {
42
+ if let Ok ( mut borrowed) = self . inner . get_from_all ( to_be_evicted ) ?. try_borrow_mut ( ) {
44
43
* borrowed. input_mut ( ) = None ;
45
44
} else {
46
- self . cached_indexes . borrow_mut ( ) . push_back ( removed ) ;
45
+ self . cached_indexes . borrow_mut ( ) . push_back ( to_be_evicted ) ;
47
46
borrowed_num += 1 ;
48
47
if self . cache_max_len == borrowed_num {
49
48
break ;
@@ -106,16 +105,12 @@ where
106
105
/// Get by id; considers only enabled testcases
107
106
#[ inline]
108
107
fn get ( & self , id : CorpusId ) -> Result < & RefCell < Testcase < I > > , Error > {
109
- let testcase = { self . inner . get ( id) ? } ;
110
- self . cache_testcase ( testcase, id) ?;
111
- Ok ( testcase)
108
+ self . inner . get ( id)
112
109
}
113
110
/// Get by id; considers both enabled and disabled testcases
114
111
#[ inline]
115
112
fn get_from_all ( & self , id : CorpusId ) -> Result < & RefCell < Testcase < I > > , Error > {
116
- let testcase = { self . inner . get_from_all ( id) ? } ;
117
- self . cache_testcase ( testcase, id) ?;
118
- Ok ( testcase)
113
+ self . inner . get_from_all ( id)
119
114
}
120
115
121
116
/// Current testcase scheduled
@@ -169,7 +164,8 @@ where
169
164
170
165
#[ inline]
171
166
fn load_input_into ( & self , testcase : & mut Testcase < I > ) -> Result < ( ) , Error > {
172
- self . inner . load_input_into ( testcase)
167
+ self . cache_testcase_input ( testcase) ?;
168
+ Ok ( ( ) )
173
169
}
174
170
175
171
#[ inline]
0 commit comments