Changed the PartialEq impl of Deque, replacing the if comparison chain with match + cmp, as requested by clippy.

This commit is contained in:
William Hicklin 2024-12-10 14:02:10 +00:00
parent 6e47051553
commit fc75aed0ff

View File

@ -34,6 +34,7 @@
//! ```
use core::borrow::{Borrow, BorrowMut};
use core::cmp::Ordering;
use core::fmt;
use core::iter::FusedIterator;
use core::mem::MaybeUninit;
@ -957,9 +958,9 @@ impl<T: PartialEq, const N: usize> PartialEq for Deque<T, N> {
}
let (sa, sb) = self.as_slices();
let (oa, ob) = other.as_slices();
if sa.len() == oa.len() {
sa == oa && sb == ob
} else if sa.len() < oa.len() {
match sa.len().cmp(&oa.len()) {
Ordering::Equal => sa == oa && sb == ob,
Ordering::Less => {
// Always divisible in three sections, for example:
// self: [a b c|d e f]
// other: [0 1 2 3|4 5]
@ -974,7 +975,8 @@ impl<T: PartialEq, const N: usize> PartialEq for Deque<T, N> {
debug_assert_eq!(sb_mid.len(), oa_mid.len());
debug_assert_eq!(sb_back.len(), ob.len());
sa == oa_front && sb_mid == oa_mid && sb_back == ob
} else {
}
Ordering::Greater => {
let front = oa.len();
let mid = sa.len() - front;
@ -987,6 +989,7 @@ impl<T: PartialEq, const N: usize> PartialEq for Deque<T, N> {
}
}
}
}
impl<T: Eq, const N: usize> Eq for Deque<T, N> {}