@@ -29,21 +29,20 @@ impl<I> CachedOnDiskCorpus<I>
2929where
3030 I : Input ,
3131{
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) ?;
3938 let mut borrowed_num = 0 ;
4039 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 ( ) ;
4241
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 ( ) {
4443 * borrowed. input_mut ( ) = None ;
4544 } else {
46- self . cached_indexes . borrow_mut ( ) . push_back ( removed ) ;
45+ self . cached_indexes . borrow_mut ( ) . push_back ( to_be_evicted ) ;
4746 borrowed_num += 1 ;
4847 if self . cache_max_len == borrowed_num {
4948 break ;
@@ -106,16 +105,12 @@ where
106105 /// Get by id; considers only enabled testcases
107106 #[ inline]
108107 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)
112109 }
113110 /// Get by id; considers both enabled and disabled testcases
114111 #[ inline]
115112 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)
119114 }
120115
121116 /// Current testcase scheduled
@@ -169,7 +164,8 @@ where
169164
170165 #[ inline]
171166 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 ( ( ) )
173169 }
174170
175171 #[ inline]
0 commit comments