Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Put the actual collection work out-of-line to reduce overhead when th…
Browse files Browse the repository at this point in the history
…ere is nothing to collect
  • Loading branch information
adamreichold committed May 20, 2024
1 parent bc9a018 commit 11fd2e4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,22 @@ where
/// Collect the values into an iterator
///
/// Dropping the iterator will drop the remaining collected values.
pub fn collect<F>(&self, mut f: F)
#[inline]
pub fn collect<F>(&self, f: F)
where
F: FnMut(T),
{
let old_top = self.0.swap(null_mut(), Ordering::AcqRel);

if old_top.is_null() {
return;
if !old_top.is_null() {
self.collect_nonnull(old_top, f);
}
}

fn collect_nonnull<F>(&self, old_top: *mut Block<T, B>, mut f: F)
where
F: FnMut(T),
{
let mut curr = old_top;

while !curr.is_null() {
Expand Down

0 comments on commit 11fd2e4

Please sign in to comment.