Skip to content

Commit

Permalink
Use unwrap_or_else for efficiency (solana-labs#31747)
Browse files Browse the repository at this point in the history
Use unwrap_or_else for efficiency.
  • Loading branch information
lijunwangs authored May 22, 2023
1 parent 2549bff commit 917f3d2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down
2 changes: 1 addition & 1 deletion rpc/src/optimistically_confirmed_bank_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 917f3d2

Please sign in to comment.