use core::slice;
use crate::SmallBytes;
use crate::heap::INLINE_LEN_MAX;
impl SmallBytes {
#[allow(clippy::inline_always)] #[inline(always)]
fn eq_inline_inline(&self, other: &Self, self_tag: u8, other_tag: u8) -> bool {
let len = self_tag as usize;
if len != other_tag as usize {
return false;
}
let a = unsafe { slice::from_raw_parts(self.inline.data.as_ptr(), len) };
let b = unsafe { slice::from_raw_parts(other.inline.data.as_ptr(), len) };
a == b
}
#[allow(clippy::inline_always)] #[inline(always)]
fn eq_heap_heap(&self, other: &Self) -> bool {
let (a_len, b_len) = unsafe { (self.heap.length(), other.heap.length()) };
if a_len != b_len {
return false;
}
let a = unsafe { slice::from_raw_parts(self.heap.ptr.as_ptr(), a_len) };
let b = unsafe { slice::from_raw_parts(other.heap.ptr.as_ptr(), b_len) };
a == b
}
}
impl PartialEq for SmallBytes {
#[inline]
fn eq(&self, other: &Self) -> bool {
let self_tag = unsafe { self.inline.tag };
let other_tag = unsafe { other.inline.tag };
let self_inline = self_tag <= INLINE_LEN_MAX;
let other_inline = other_tag <= INLINE_LEN_MAX;
match (self_inline, other_inline) {
(true, true) => self.eq_inline_inline(other, self_tag, other_tag),
(false, false) => self.eq_heap_heap(other),
_ => self.as_slice() == other.as_slice(),
}
}
}
impl Eq for SmallBytes {}