move remove_if_slot_list_empty to InMemAccountsIndex (#19801)

This commit is contained in:
Jeff Washington (jwash)
2021-09-12 10:26:04 -05:00
committed by GitHub
parent 361101bd31
commit a295febf04
2 changed files with 13 additions and 17 deletions

View File

@@ -42,6 +42,18 @@ impl<T: IsCached> InMemAccountsIndex<T> {
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()
}