Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
AmbientTea committed Feb 26, 2025
1 parent e03cd18 commit 100d637
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions toolkit/pallets/block-production-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ pub mod pallet {

impl<T: Config> Pallet<T> {
pub fn take_prefix(slot: &Slot) -> Vec<(Slot, T::BlockProducerId)> {
let (to_return, to_retain) = Log::<T>::get().into_iter().partition(|(s, _)| s <= slot);
Log::<T>::put(to_retain);
to_return
let removed_prefix = Log::<T>::mutate(|log| {
let pos = log.partition_point(|(s, _)| s <= slot);
log.drain(..pos).collect()
});
removed_prefix
}

pub fn peek_prefix(slot: Slot) -> impl Iterator<Item = (Slot, T::BlockProducerId)> {
Expand Down

0 comments on commit 100d637

Please sign in to comment.