acctidx: avoid extra addref in combine ancient slots (#27545)

* acctidx: avoid extra addref in combine ancient slots

* make code common
This commit is contained in:
Jeff Washington (jwash) 2022-09-06 13:57:34 -07:00 committed by GitHub
parent a67d56f462
commit ecbd5bb807
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 8 deletions

View File

@ -632,13 +632,13 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
if matched_slot {
found_slot = true;
if !is_cur_account_cached {
// current info at 'slot' is NOT cached, so we should NOT addref. This slot already has a ref count for this pubkey.
addref = false;
}
} else {
found_other_slot = true;
}
if !is_cur_account_cached {
// current info at 'slot' is NOT cached, so we should NOT addref. This slot already has a ref count for this pubkey.
addref = false;
}
}
});
if !found_slot && !found_other_slot {
@ -1721,8 +1721,10 @@ mod tests {
let other_slot = Some(unique_other_slot);
let mut reclaims = Vec::default();
assert!(
// upserting into slot_list that does NOT contain an entry at 'new-slot', so always addref
InMemAccountsIndex::update_slot_list(
// upserting into slot_list that does NOT contain an entry at 'new_slot'
// but, it DOES contain an entry at other_slot, so we do NOT add-ref. The assumption is that 'other_slot' is going away
// and that the previously held add-ref is now used by 'new_slot'
!InMemAccountsIndex::update_slot_list(
&mut slot_list,
new_slot,
info,
@ -1827,8 +1829,10 @@ mod tests {
// calculate expected results
let mut expected_reclaims = Vec::default();
// addref iff the slot_list did NOT previously contain an entry at 'new_slot'
let expected_result = !expected.iter().any(|(slot, _info)| slot == &new_slot);
// addref iff the slot_list did NOT previously contain an entry at 'new_slot' and it also did not contain an entry at 'other_slot'
let expected_result = !expected
.iter()
.any(|(slot, _info)| slot == &new_slot || Some(*slot) == other_slot);
{
// this is the logical equivalent of 'InMemAccountsIndex::update_slot_list', but slower (and ignoring addref)
expected.retain(|(slot, info)| {