Skip to content

Commit

Permalink
use Peekable::next_if() (openzfs#488)
Browse files Browse the repository at this point in the history
code cleanup: use this std library function now that we're on a newer version of Rust that includes it.
  • Loading branch information
ahrens authored Oct 5, 2021
1 parent d2b0426 commit 0d5e669
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions cmd/zfs_object_agent/zettaobject/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,9 +1135,7 @@ impl Pool {
syncing_state.pending_object = PendingObjectState::NotPending(next_block);

// skip over writes that were moved to pending_object and written out
while peekable_next_if(&mut ordered_writes_iter, |b| b < &next_block)
.is_some()
{}
while ordered_writes_iter.next_if(|&b| b < next_block).is_some() {}
}
_ => {
// already-written object is next
Expand All @@ -1153,9 +1151,7 @@ impl Pool {
// case we will not create an object, since the blocks are
// already persistent, so we need to notify the waiter now.
while let Some(obsolete_write) =
peekable_next_if(&mut ordered_writes_iter, |b| {
b < &recovered_obj.next_block
})
ordered_writes_iter.next_if(|&b| b < recovered_obj.next_block)
{
trace!(
"resume: {:?} is obsoleted by existing {:?}",
Expand Down Expand Up @@ -2642,17 +2638,6 @@ async fn try_condense_object_sizes(
);
}

// This works like Peekable::next_if(), which isn't available in the version of Rust that we use.
fn peekable_next_if<I: Iterator>(
this: &mut std::iter::Peekable<I>,
func: impl FnOnce(&I::Item) -> bool,
) -> Option<I::Item> {
match this.peek() {
Some(matched) if func(matched) => this.next(),
_ => None,
}
}

fn clean_metadata(
state: Arc<PoolState>,
syncing_state: &mut PoolSyncingState,
Expand Down

0 comments on commit 0d5e669

Please sign in to comment.