From ebabc53cee67bbba6c420ecd8756a2d3848c8f75 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Sun, 31 Jul 2022 21:04:15 -0500 Subject: [PATCH] use Vec::drain instead of option/take (#26852) --- runtime/src/in_mem_accounts_index.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 4d9042cfe7..89babf1dad 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -77,9 +77,9 @@ struct StartupInfo { /// result from scanning in-mem index during flush struct FlushScanResult { /// pubkeys whose age indicates they may be evicted now, pending further checks. - evictions_age_possible: Vec<(Pubkey, Option>)>, + evictions_age_possible: Vec<(Pubkey, AccountMapEntry)>, /// pubkeys chosen to evict based on random eviction - evictions_random: Vec<(Pubkey, Option>)>, + evictions_random: Vec<(Pubkey, AccountMapEntry)>, } impl InMemAccountsIndex { @@ -992,7 +992,7 @@ impl InMemAccountsIndex { } else { &mut evictions_age_possible } - .push((*k, Some(Arc::clone(v)))); + .push((*k, Arc::clone(v))); } } Self::update_time_stat(&self.stats().flush_scan_us, m); @@ -1104,8 +1104,7 @@ impl InMemAccountsIndex { (false, &mut evictions_age_possible), (true, &mut evictions_random), ] { - for (k, v) in check_for_eviction_and_dirty { - let v = v.take().unwrap(); + for (k, v) in check_for_eviction_and_dirty.drain(..) { let mut slot_list = None; if !is_random { let mut mse = Measure::start("flush_should_evict"); @@ -1120,7 +1119,7 @@ impl InMemAccountsIndex { mse.stop(); flush_should_evict_us += mse.as_us(); if evict_for_age { - evictions_age.push(*k); + evictions_age.push(k); } else { // not evicting, so don't write, even if dirty continue; @@ -1142,7 +1141,7 @@ impl InMemAccountsIndex { let slot_list = slot_list .take() .unwrap_or_else(|| v.slot_list.read().unwrap()); - disk.try_write(k, (&slot_list, v.ref_count())) + disk.try_write(&k, (&slot_list, v.ref_count())) }; match disk_resize { Ok(_) => {