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:
parent
a67d56f462
commit
ecbd5bb807
|
@ -632,13 +632,13 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
|
||||||
|
|
||||||
if matched_slot {
|
if matched_slot {
|
||||||
found_slot = true;
|
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 {
|
} else {
|
||||||
found_other_slot = true;
|
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 {
|
if !found_slot && !found_other_slot {
|
||||||
|
@ -1721,8 +1721,10 @@ mod tests {
|
||||||
let other_slot = Some(unique_other_slot);
|
let other_slot = Some(unique_other_slot);
|
||||||
let mut reclaims = Vec::default();
|
let mut reclaims = Vec::default();
|
||||||
assert!(
|
assert!(
|
||||||
// upserting into slot_list that does NOT contain an entry at 'new-slot', so always addref
|
// upserting into slot_list that does NOT contain an entry at 'new_slot'
|
||||||
InMemAccountsIndex::update_slot_list(
|
// 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,
|
&mut slot_list,
|
||||||
new_slot,
|
new_slot,
|
||||||
info,
|
info,
|
||||||
|
@ -1827,8 +1829,10 @@ mod tests {
|
||||||
|
|
||||||
// calculate expected results
|
// calculate expected results
|
||||||
let mut expected_reclaims = Vec::default();
|
let mut expected_reclaims = Vec::default();
|
||||||
// addref iff the slot_list did NOT previously contain an entry at '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);
|
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)
|
// this is the logical equivalent of 'InMemAccountsIndex::update_slot_list', but slower (and ignoring addref)
|
||||||
expected.retain(|(slot, info)| {
|
expected.retain(|(slot, info)| {
|
||||||
|
|
Loading…
Reference in New Issue