include!(concat!(env!("OUT_DIR"), "/compare.rs"));
macro_rules! cmp (
($left:expr, $right: expr, $var:ident, $offset:expr) => {
unsafe {*($left.offset($offset) as *const $var) == *($right.offset($offset) as *const $var)}
}
);
pub trait Compare {
fn feq(self: &Self, to: &Self) -> bool;
}
impl Compare for [u8] {
#[cfg_attr(feature = "cargo-clippy", allow(inline_always))]
#[inline(always)]
fn feq(&self, to: &[u8]) -> bool {
extern "C" {
fn memcmp(s1: *const i8, s2: *const i8, n: usize) -> i32;
}
let a = to.as_ptr() as *const i8;
let b = self.as_ptr() as *const i8;
let len = to.len();
self.len() == len && slice_compare!(a, b, len)
}
}