Skip to content

Commit

Permalink
use scan_accounts to replace account_iter (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Apr 22, 2024
1 parent 43e47be commit 8d4f2e6
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6662,7 +6662,7 @@ impl AccountsDb {
where
S: AppendVecScan,
{
storage.accounts.account_iter().for_each(|account| {
storage.accounts.scan_accounts(|account| {
if scanner.filter(account.pubkey()) {
scanner.found_account(&LoadedAccount::Stored(account))
}
Expand Down Expand Up @@ -8806,7 +8806,7 @@ impl AccountsDb {
// verify index matches expected and measure the time to get all items
assert!(verify);
let mut lookup_time = Measure::start("lookup_time");
for account_info in storage.accounts.account_iter() {
storage.accounts.scan_accounts(|account_info| {
let key = account_info.pubkey();
let index_entry = self.accounts_index.get_cloned(key).unwrap();
let slot_list = index_entry.slot_list.read().unwrap();
Expand All @@ -8825,7 +8825,7 @@ impl AccountsDb {
}
}
assert_eq!(1, count);
}
});
lookup_time.stop();
lookup_time.as_us()
};
Expand Down Expand Up @@ -9334,16 +9334,13 @@ impl AccountsDb {
}

pub fn sizes_of_accounts_in_storage_for_tests(&self, slot: Slot) -> Vec<usize> {
self.storage
.get_slot_storage_entry(slot)
.map(|storage| {
storage
.accounts
.account_iter()
.map(|account| account.stored_size())
.collect()
})
.unwrap_or_default()
let mut sizes = Vec::default();
if let Some(storage) = self.storage.get_slot_storage_entry(slot) {
storage.accounts.scan_accounts(|account| {
sizes.push(account.stored_size());
});
}
sizes
}

pub fn ref_count_for_pubkey(&self, pubkey: &Pubkey) -> RefCount {
Expand Down Expand Up @@ -17017,7 +17014,7 @@ pub mod tests {
fn populate_index(db: &AccountsDb, slots: Range<Slot>) {
slots.into_iter().for_each(|slot| {
if let Some(storage) = db.get_storage_for_slot(slot) {
storage.accounts.account_iter().for_each(|account| {
storage.accounts.scan_accounts(|account| {
let info = AccountInfo::new(
StorageLocation::AppendVec(storage.append_vec_id(), account.offset()),
account.lamports(),
Expand Down

0 comments on commit 8d4f2e6

Please sign in to comment.