Adds AccountsIndex::get_account_info_with_and_then() (#35336)
This commit is contained in:
parent
da088681ba
commit
a4e1a9ac98
|
@ -1143,18 +1143,30 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
|
||||||
ancestors: Option<&Ancestors>,
|
ancestors: Option<&Ancestors>,
|
||||||
max_root: Option<Slot>,
|
max_root: Option<Slot>,
|
||||||
should_add_to_in_mem_cache: bool,
|
should_add_to_in_mem_cache: bool,
|
||||||
mut callback: impl FnMut((Slot, T)) -> R,
|
callback: impl FnOnce((Slot, T)) -> R,
|
||||||
) -> Option<R> {
|
) -> Option<R> {
|
||||||
self.get_and_then(pubkey, |entry| {
|
self.get_and_then(pubkey, |entry| {
|
||||||
let callback_result = entry.and_then(|entry| {
|
let callback_result = entry.and_then(|entry| {
|
||||||
let slot_list = entry.slot_list.read().unwrap();
|
self.get_account_info_with_and_then(entry, ancestors, max_root, callback)
|
||||||
self.latest_slot(ancestors, &slot_list, max_root)
|
|
||||||
.map(|found_index| callback(slot_list[found_index]))
|
|
||||||
});
|
});
|
||||||
(should_add_to_in_mem_cache, callback_result)
|
(should_add_to_in_mem_cache, callback_result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the account info (and slot) in `entry`, with `ancestors` and `max_root`,
|
||||||
|
/// and applies `callback` to it
|
||||||
|
fn get_account_info_with_and_then<R>(
|
||||||
|
&self,
|
||||||
|
entry: &AccountMapEntryInner<T>,
|
||||||
|
ancestors: Option<&Ancestors>,
|
||||||
|
max_root: Option<Slot>,
|
||||||
|
callback: impl FnOnce((Slot, T)) -> R,
|
||||||
|
) -> Option<R> {
|
||||||
|
let slot_list = entry.slot_list.read().unwrap();
|
||||||
|
self.latest_slot(ancestors, &slot_list, max_root)
|
||||||
|
.map(|found_index| callback(slot_list[found_index]))
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets the index's entry for `pubkey` and clones it
|
/// Gets the index's entry for `pubkey` and clones it
|
||||||
///
|
///
|
||||||
/// Prefer `get_and_then()` whenever possible.
|
/// Prefer `get_and_then()` whenever possible.
|
||||||
|
|
Loading…
Reference in New Issue