diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index 5877808903..b283186383 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -1234,7 +1234,7 @@ impl AccountsIndex { if !dead_keys.is_empty() { for key in dead_keys.iter() { let mut w_index = self.get_account_maps_write_lock(key); - if self.remove_if_slot_list_empty(key, &mut w_index) { + if w_index.remove_if_slot_list_empty(**key) { // Note it's only safe to remove all the entries for this key // because we have the lock for this key's entry in the AccountsIndex, // so no other thread is also updating the index @@ -1244,22 +1244,6 @@ impl AccountsIndex { } } - // If the slot list for pubkey exists in the index and is empty, remove the index entry for pubkey and return true. - // Return false otherwise. - fn remove_if_slot_list_empty( - &self, - pubkey: &Pubkey, - lock: &mut AccountMapsWriteLock, - ) -> bool { - if let Entry::Occupied(index_entry) = lock.entry(*pubkey) { - if index_entry.get().slot_list.read().unwrap().is_empty() { - index_entry.remove(); - return true; - } - } - false - } - /// call func with every pubkey and index visible from a given set of ancestors pub(crate) fn scan_accounts( &self, diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index d7e790dad3..87e7cfeedb 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -42,6 +42,18 @@ impl InMemAccountsIndex { self.map.remove(key); } + // If the slot list for pubkey exists in the index and is empty, remove the index entry for pubkey and return true. + // Return false otherwise. + pub fn remove_if_slot_list_empty(&mut self, pubkey: Pubkey) -> bool { + if let Entry::Occupied(index_entry) = self.map.entry(pubkey) { + if index_entry.get().slot_list.read().unwrap().is_empty() { + index_entry.remove(); + return true; + } + } + false + } + pub fn len(&self) -> usize { self.map.len() }