@@ -29,22 +29,22 @@ impl<'a, T: 'a + Clone> AccountsIndex<T> {
2929 {
3030 for ( pubkey, list) in iter {
3131 let list_r = & list. 1 . read ( ) . unwrap ( ) ;
32- if let Some ( index) = self . latest_slot ( ancestors, & list_r) {
32+ if let Some ( index) = self . latest_slot ( Some ( ancestors) , & list_r) {
3333 func ( pubkey, ( & list_r[ index] . 1 , list_r[ index] . 0 ) ) ;
3434 }
3535 }
3636 }
3737
3838 /// call func with every pubkey and index visible from a given set of ancestors
39- pub fn scan_accounts < F > ( & self , ancestors : & Ancestors , func : F )
39+ pub ( crate ) fn scan_accounts < F > ( & self , ancestors : & Ancestors , func : F )
4040 where
4141 F : FnMut ( & Pubkey , ( & T , Slot ) ) ,
4242 {
4343 self . do_scan_accounts ( ancestors, func, self . account_maps . iter ( ) ) ;
4444 }
4545
4646 /// call func with every pubkey and index visible from a given set of ancestors with range
47- pub fn range_scan_accounts < F , R > ( & self , ancestors : & Ancestors , range : R , func : F )
47+ pub ( crate ) fn range_scan_accounts < F , R > ( & self , ancestors : & Ancestors , range : R , func : F )
4848 where
4949 F : FnMut ( & Pubkey , ( & T , Slot ) ) ,
5050 R : RangeBounds < Pubkey > ,
@@ -76,11 +76,14 @@ impl<'a, T: 'a + Clone> AccountsIndex<T> {
7676
7777 // find the latest slot and T in a slice for a given ancestor
7878 // returns index into 'slice' if found, None if not.
79- fn latest_slot ( & self , ancestors : & Ancestors , slice : SlotSlice < T > ) -> Option < usize > {
79+ fn latest_slot ( & self , ancestors : Option < & Ancestors > , slice : SlotSlice < T > ) -> Option < usize > {
8080 let mut max = 0 ;
8181 let mut rv = None ;
8282 for ( i, ( slot, _t) ) in slice. iter ( ) . rev ( ) . enumerate ( ) {
83- if * slot >= max && ( ancestors. contains_key ( slot) || self . is_root ( * slot) ) {
83+ if * slot >= max
84+ && ( ancestors. map_or ( false , |ancestors| ancestors. contains_key ( slot) )
85+ || self . is_root ( * slot) )
86+ {
8487 rv = Some ( ( slice. len ( ) - 1 ) - i) ;
8588 max = * slot;
8689 }
@@ -90,10 +93,10 @@ impl<'a, T: 'a + Clone> AccountsIndex<T> {
9093
9194 /// Get an account
9295 /// The latest account that appears in `ancestors` or `roots` is returned.
93- pub fn get (
96+ pub ( crate ) fn get (
9497 & self ,
9598 pubkey : & Pubkey ,
96- ancestors : & Ancestors ,
99+ ancestors : Option < & Ancestors > ,
97100 ) -> Option < ( RwLockReadGuard < SlotList < T > > , usize ) > {
98101 self . account_maps . get ( pubkey) . and_then ( |list| {
99102 let list_r = list. 1 . read ( ) . unwrap ( ) ;
@@ -245,7 +248,8 @@ mod tests {
245248 let key = Keypair :: new ( ) ;
246249 let index = AccountsIndex :: < bool > :: default ( ) ;
247250 let ancestors = HashMap :: new ( ) ;
248- assert ! ( index. get( & key. pubkey( ) , & ancestors) . is_none( ) ) ;
251+ assert ! ( index. get( & key. pubkey( ) , Some ( & ancestors) ) . is_none( ) ) ;
252+ assert ! ( index. get( & key. pubkey( ) , None ) . is_none( ) ) ;
249253
250254 let mut num = 0 ;
251255 index. scan_accounts ( & ancestors, |_pubkey, _index| num += 1 ) ;
@@ -261,7 +265,8 @@ mod tests {
261265 assert ! ( gc. is_empty( ) ) ;
262266
263267 let ancestors = HashMap :: new ( ) ;
264- assert ! ( index. get( & key. pubkey( ) , & ancestors) . is_none( ) ) ;
268+ assert ! ( index. get( & key. pubkey( ) , Some ( & ancestors) ) . is_none( ) ) ;
269+ assert ! ( index. get( & key. pubkey( ) , None ) . is_none( ) ) ;
265270
266271 let mut num = 0 ;
267272 index. scan_accounts ( & ancestors, |_pubkey, _index| num += 1 ) ;
@@ -277,7 +282,7 @@ mod tests {
277282 assert ! ( gc. is_empty( ) ) ;
278283
279284 let ancestors = vec ! [ ( 1 , 1 ) ] . into_iter ( ) . collect ( ) ;
280- assert ! ( index. get( & key. pubkey( ) , & ancestors) . is_none( ) ) ;
285+ assert ! ( index. get( & key. pubkey( ) , Some ( & ancestors) ) . is_none( ) ) ;
281286
282287 let mut num = 0 ;
283288 index. scan_accounts ( & ancestors, |_pubkey, _index| num += 1 ) ;
@@ -293,7 +298,7 @@ mod tests {
293298 assert ! ( gc. is_empty( ) ) ;
294299
295300 let ancestors = vec ! [ ( 0 , 0 ) ] . into_iter ( ) . collect ( ) ;
296- let ( list, idx) = index. get ( & key. pubkey ( ) , & ancestors) . unwrap ( ) ;
301+ let ( list, idx) = index. get ( & key. pubkey ( ) , Some ( & ancestors) ) . unwrap ( ) ;
297302 assert_eq ! ( list[ idx] , ( 0 , true ) ) ;
298303
299304 let mut num = 0 ;
@@ -324,9 +329,8 @@ mod tests {
324329 index. insert ( 0 , & key. pubkey ( ) , true , & mut gc) ;
325330 assert ! ( gc. is_empty( ) ) ;
326331
327- let ancestors = vec ! [ ] . into_iter ( ) . collect ( ) ;
328332 index. add_root ( 0 ) ;
329- let ( list, idx) = index. get ( & key. pubkey ( ) , & ancestors ) . unwrap ( ) ;
333+ let ( list, idx) = index. get ( & key. pubkey ( ) , None ) . unwrap ( ) ;
330334 assert_eq ! ( list[ idx] , ( 0 , true ) ) ;
331335 }
332336
@@ -369,14 +373,14 @@ mod tests {
369373 let mut gc = Vec :: new ( ) ;
370374 index. insert ( 0 , & key. pubkey ( ) , true , & mut gc) ;
371375 assert ! ( gc. is_empty( ) ) ;
372- let ( list, idx) = index. get ( & key. pubkey ( ) , & ancestors) . unwrap ( ) ;
376+ let ( list, idx) = index. get ( & key. pubkey ( ) , Some ( & ancestors) ) . unwrap ( ) ;
373377 assert_eq ! ( list[ idx] , ( 0 , true ) ) ;
374378 drop ( list) ;
375379
376380 let mut gc = Vec :: new ( ) ;
377381 index. insert ( 0 , & key. pubkey ( ) , false , & mut gc) ;
378382 assert_eq ! ( gc, vec![ ( 0 , true ) ] ) ;
379- let ( list, idx) = index. get ( & key. pubkey ( ) , & ancestors) . unwrap ( ) ;
383+ let ( list, idx) = index. get ( & key. pubkey ( ) , Some ( & ancestors) ) . unwrap ( ) ;
380384 assert_eq ! ( list[ idx] , ( 0 , false ) ) ;
381385 }
382386
@@ -391,10 +395,10 @@ mod tests {
391395 assert ! ( gc. is_empty( ) ) ;
392396 index. insert ( 1 , & key. pubkey ( ) , false , & mut gc) ;
393397 assert ! ( gc. is_empty( ) ) ;
394- let ( list, idx) = index. get ( & key. pubkey ( ) , & ancestors) . unwrap ( ) ;
398+ let ( list, idx) = index. get ( & key. pubkey ( ) , Some ( & ancestors) ) . unwrap ( ) ;
395399 assert_eq ! ( list[ idx] , ( 0 , true ) ) ;
396400 let ancestors = vec ! [ ( 1 , 0 ) ] . into_iter ( ) . collect ( ) ;
397- let ( list, idx) = index. get ( & key. pubkey ( ) , & ancestors) . unwrap ( ) ;
401+ let ( list, idx) = index. get ( & key. pubkey ( ) , Some ( & ancestors) ) . unwrap ( ) ;
398402 assert_eq ! ( list[ idx] , ( 1 , false ) ) ;
399403 }
400404
@@ -413,13 +417,12 @@ mod tests {
413417 index. add_root ( 3 ) ;
414418 index. insert ( 4 , & key. pubkey ( ) , true , & mut gc) ;
415419 assert_eq ! ( gc, vec![ ( 0 , true ) , ( 1 , false ) , ( 2 , true ) ] ) ;
416- let ancestors = vec ! [ ] . into_iter ( ) . collect ( ) ;
417- let ( list, idx) = index. get ( & key. pubkey ( ) , & ancestors) . unwrap ( ) ;
420+ let ( list, idx) = index. get ( & key. pubkey ( ) , None ) . unwrap ( ) ;
418421 assert_eq ! ( list[ idx] , ( 3 , true ) ) ;
419422
420423 let mut num = 0 ;
421424 let mut found_key = false ;
422- index. scan_accounts ( & ancestors , |pubkey, _index| {
425+ index. scan_accounts ( & Ancestors :: new ( ) , |pubkey, _index| {
423426 if pubkey == & key. pubkey ( ) {
424427 found_key = true ;
425428 assert_eq ! ( _index, ( & true , 3 ) ) ;
0 commit comments