Skip to content

Commit

Permalink
fix: remove length check for the empty vector
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Oct 23, 2023
1 parent 561d57b commit 555dff3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,12 +819,6 @@ impl<T: Copy> LockFreeFrozenVec<T> {
/// - `func`: a function that takes a slice to the buffer and the buffer index
///
fn for_each_buffer(&self, mut func: impl FnMut(&[T], usize)) {
let len = self.len.load(Ordering::Acquire);
// handle the empty case
if len == 0 {
return;
}

// for each buffer, run the function
for buffer_index in 0..NUM_BUFFERS {
// get the buffer pointer
Expand Down Expand Up @@ -959,6 +953,12 @@ fn test_non_lockfree() {
assert_eq!(large_vec_2.get(i), Some(Moo(i as i32)));
}
}
// Test cloning an empty vector
{
let empty_vec = LockFreeFrozenVec::<()>::new();
let empty_vec_2 = empty_vec.clone();
assert_eq!(empty_vec_2.get(0), None);
}

// Test dropping empty vecs
LockFreeFrozenVec::<()>::new();
Expand Down

0 comments on commit 555dff3

Please sign in to comment.