diff --git a/crossbeam-channel/src/flavors/at.rs b/crossbeam-channel/src/flavors/at.rs index ca5ee60f5..070e989d6 100644 --- a/crossbeam-channel/src/flavors/at.rs +++ b/crossbeam-channel/src/flavors/at.rs @@ -134,11 +134,7 @@ impl Channel { /// Returns the number of messages in the channel. #[inline] pub(crate) fn len(&self) -> usize { - if self.is_empty() { - 0 - } else { - 1 - } + usize::from(!self.is_empty()) } /// Returns the capacity of the channel. diff --git a/crossbeam-channel/src/flavors/tick.rs b/crossbeam-channel/src/flavors/tick.rs index 4201b6eb0..484825dc8 100644 --- a/crossbeam-channel/src/flavors/tick.rs +++ b/crossbeam-channel/src/flavors/tick.rs @@ -105,11 +105,7 @@ impl Channel { /// Returns the number of messages in the channel. #[inline] pub(crate) fn len(&self) -> usize { - if self.is_empty() { - 0 - } else { - 1 - } + usize::from(!self.is_empty()) } /// Returns the capacity of the channel. diff --git a/crossbeam-skiplist/src/base.rs b/crossbeam-skiplist/src/base.rs index d27c531b5..df3cead64 100644 --- a/crossbeam-skiplist/src/base.rs +++ b/crossbeam-skiplist/src/base.rs @@ -36,7 +36,7 @@ impl Index for Tower { fn index(&self, index: usize) -> &Atomic> { // This implementation is actually unsafe since we don't check if the // index is in-bounds. But this is fine since this is only used internally. - unsafe { self.pointers.get_unchecked(index) } + unsafe { &*(&self.pointers as *const Atomic>).add(index) } } } @@ -1718,7 +1718,7 @@ where }; match (&next_head, &self.tail) { // The next key is larger than the latest tail key we observed with this iterator. - (Some(ref next), &Some(ref t)) if next.key() >= t.key() => { + (Some(ref next), Some(t)) if next.key() >= t.key() => { unsafe { next.node.decrement(guard); } @@ -1745,7 +1745,7 @@ where }; match (&self.head, &next_tail) { // The prev key is smaller than the latest head key we observed with this iterator. - (&Some(ref h), Some(next)) if h.key() >= next.key() => { + (Some(h), Some(next)) if h.key() >= next.key() => { unsafe { next.node.decrement(guard); }