Use unwrap_or_else for efficiency (#31747)

Use unwrap_or_else for efficiency.
This commit is contained in:
Lijun Wang 2023-05-22 09:58:24 -07:00 committed by GitHub
parent 2549bff59c
commit 917f3d2586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -2118,7 +2118,7 @@ impl ReplayStage {
.map_or(false, |sender| sender.should_send_parents)
.then(|| {
let mut new_chain = rooted_slots.clone();
new_chain.push(oldest_parent.unwrap_or(bank.parent_slot()));
new_chain.push(oldest_parent.unwrap_or_else(|| bank.parent_slot()));
new_chain
});

View File

@ -396,7 +396,7 @@ mod tests {
let oldest_parent = parents.last().map(|last| last.parent_slot());
parents.push(bank.clone());
let mut rooted_slots: Vec<_> = parents.iter().map(|bank| bank.slot()).collect();
rooted_slots.push(oldest_parent.unwrap_or(bank.parent_slot()));
rooted_slots.push(oldest_parent.unwrap_or_else(|| bank.parent_slot()));
rooted_slots
}