Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy lint in mpmc and linear_map #413

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/linear_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,27 +441,20 @@ where
}
}

#[derive(Clone, Debug)]
pub struct Iter<'a, K, V> {
iter: slice::Iter<'a, (K, V)>,
}

impl<'a, K, V> Iterator for Iter<'a, K, V> {
type Item = (&'a K, &'a V);

#[allow(clippy::needless_borrowed_reference)]
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|&(ref k, ref v)| (k, v))
}
}

impl<'a, K, V> Clone for Iter<'a, K, V> {
fn clone(&self) -> Self {
Self {
iter: self.iter.clone(),
}
self.iter.next().map(|(k, v)| (k, v))
}
}

#[derive(Debug)]
pub struct IterMut<'a, K, V> {
iter: slice::IterMut<'a, (K, V)>,
}
Expand All @@ -470,7 +463,7 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> {
type Item = (&'a K, &'a mut V);

fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(|&mut (ref k, ref mut v)| (k, v))
self.iter.next().map(|(k, v)| (k as &K, v))
}
}

Expand Down
70 changes: 38 additions & 32 deletions src/mpmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ impl<T> Cell<T> {
}
}

#[allow(clippy::comparison_chain)]
unsafe fn dequeue<T>(
buffer: *mut Cell<T>,
dequeue_pos: &AtomicTargetSize,
Expand All @@ -219,22 +218,26 @@ unsafe fn dequeue<T>(
let seq = (*cell).sequence.load(Ordering::Acquire);
let dif = (seq as i8).wrapping_sub((pos.wrapping_add(1)) as i8);

if dif == 0 {
if dequeue_pos
.compare_exchange_weak(
pos,
pos.wrapping_add(1),
Ordering::Relaxed,
Ordering::Relaxed,
)
.is_ok()
{
break;
match dif.cmp(&0) {
core::cmp::Ordering::Equal => {
if dequeue_pos
.compare_exchange_weak(
pos,
pos.wrapping_add(1),
Ordering::Relaxed,
Ordering::Relaxed,
)
.is_ok()
{
break;
}
}
core::cmp::Ordering::Less => {
return None;
}
core::cmp::Ordering::Greater => {
pos = dequeue_pos.load(Ordering::Relaxed);
}
} else if dif < 0 {
return None;
} else {
pos = dequeue_pos.load(Ordering::Relaxed);
}
}

Expand All @@ -245,7 +248,6 @@ unsafe fn dequeue<T>(
Some(data)
}

#[allow(clippy::comparison_chain)]
unsafe fn enqueue<T>(
buffer: *mut Cell<T>,
enqueue_pos: &AtomicTargetSize,
Expand All @@ -260,22 +262,26 @@ unsafe fn enqueue<T>(
let seq = (*cell).sequence.load(Ordering::Acquire);
let dif = (seq as i8).wrapping_sub(pos as i8);

if dif == 0 {
if enqueue_pos
.compare_exchange_weak(
pos,
pos.wrapping_add(1),
Ordering::Relaxed,
Ordering::Relaxed,
)
.is_ok()
{
break;
match dif.cmp(&0) {
core::cmp::Ordering::Equal => {
if enqueue_pos
.compare_exchange_weak(
pos,
pos.wrapping_add(1),
Ordering::Relaxed,
Ordering::Relaxed,
)
.is_ok()
{
break;
}
}
core::cmp::Ordering::Less => {
return Err(item);
}
core::cmp::Ordering::Greater => {
pos = enqueue_pos.load(Ordering::Relaxed);
}
} else if dif < 0 {
return Err(item);
} else {
pos = enqueue_pos.load(Ordering::Relaxed);
}
}

Expand Down
Loading