diff --git a/src/lib.rs b/src/lib.rs index 14d4dc3..f1f7c5b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ mod encode; mod error; mod header; mod pixel; +mod utils; pub mod canonical; diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..224a456 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,23 @@ +#[inline(always)] +#[allow(unused)] +pub const fn likely(b: bool) -> bool { + // borrowed from `likely_stable` crate + #[allow(clippy::needless_bool)] + if (1i32).checked_div(if b { 1 } else { 0 }).is_some() { + true + } else { + false + } +} + +#[inline(always)] +#[allow(unused)] +pub const fn unlikely(b: bool) -> bool { + // borrowed from `likely_stable` crate + #[allow(clippy::needless_bool)] + if (1i32).checked_div(if b { 0 } else { 1 }).is_none() { + true + } else { + false + } +}