From 691bea877682ea0ff2d6f918a0fd94c7831d81a7 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Tue, 14 Sep 2021 23:08:17 -0500 Subject: [PATCH] extract map to map() (#19883) --- runtime/src/in_mem_accounts_index.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 523f7a193b..9711c48164 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -18,7 +18,7 @@ type K = Pubkey; #[derive(Debug)] pub struct InMemAccountsIndex { // backing store - map: RwLock>>, + map_internal: RwLock>>, storage: Arc>, bin: usize, } @@ -26,12 +26,16 @@ pub struct InMemAccountsIndex { impl InMemAccountsIndex { pub fn new(storage: &AccountsIndexStorage, bin: usize) -> Self { Self { - map: RwLock::default(), + map_internal: RwLock::default(), storage: storage.storage().clone(), bin, } } + fn map(&self) -> &RwLock>> { + &self.map_internal + } + pub fn new_bucket_map_holder() -> Arc> { Arc::new(BucketMapHolder::new()) } @@ -41,7 +45,7 @@ impl InMemAccountsIndex { R: RangeBounds + std::fmt::Debug, { Self::update_stat(&self.stats().items, 1); - let map = self.map.read().unwrap(); + let map = self.map().read().unwrap(); let mut result = Vec::with_capacity(map.len()); map.iter().for_each(|(k, v)| { if range.map(|range| range.contains(k)).unwrap_or(true) { @@ -53,12 +57,12 @@ impl InMemAccountsIndex { pub fn keys(&self) -> Vec { Self::update_stat(&self.stats().keys, 1); - self.map.read().unwrap().keys().cloned().collect() + self.map().read().unwrap().keys().cloned().collect() } pub fn get(&self, key: &K) -> Option> { let m = Measure::start("get"); - let result = self.map.read().unwrap().get(key).cloned(); + let result = self.map().read().unwrap().get(key).cloned(); let stats = self.stats(); let (count, time) = if result.is_some() { (&stats.gets_from_mem, &stats.get_mem_us) @@ -74,7 +78,7 @@ impl InMemAccountsIndex { // Return false otherwise. pub fn remove_if_slot_list_empty(&mut self, pubkey: Pubkey) -> bool { let m = Measure::start("entry"); - let mut map = self.map.write().unwrap(); + let mut map = self.map().write().unwrap(); let entry = map.entry(pubkey); let stats = &self.storage.stats; let (count, time) = if matches!(entry, Entry::Occupied(_)) { @@ -103,7 +107,7 @@ impl InMemAccountsIndex { previous_slot_entry_was_cached: bool, ) { let m = Measure::start("entry"); - let mut map = self.map.write().unwrap(); + let mut map = self.map().write().unwrap(); let entry = map.entry(*pubkey); let stats = &self.storage.stats; let (count, time) = if matches!(entry, Entry::Occupied(_)) { @@ -197,7 +201,7 @@ impl InMemAccountsIndex { reclaims: &mut SlotList, previous_slot_entry_was_cached: bool, ) -> bool { - if let Some(current) = self.map.read().unwrap().get(pubkey) { + if let Some(current) = self.map().read().unwrap().get(pubkey) { Self::lock_and_update_slot_list( current, new_value, @@ -211,7 +215,7 @@ impl InMemAccountsIndex { } pub fn len(&self) -> usize { - self.map.read().unwrap().len() + self.map().read().unwrap().len() } pub fn is_empty(&self) -> bool { @@ -226,7 +230,7 @@ impl InMemAccountsIndex { new_entry: AccountMapEntry, ) -> Option<(WriteAccountMapEntry, T, Pubkey)> { let m = Measure::start("entry"); - let mut map = self.map.write().unwrap(); + let mut map = self.map().write().unwrap(); let entry = map.entry(pubkey); let stats = &self.storage.stats; let (count, time) = if matches!(entry, Entry::Occupied(_)) {