Add stable likely/unlikely to utils module
This commit is contained in:
parent
1bb6ee118c
commit
09976fb889
2 changed files with 24 additions and 0 deletions
|
@ -5,6 +5,7 @@ mod encode;
|
||||||
mod error;
|
mod error;
|
||||||
mod header;
|
mod header;
|
||||||
mod pixel;
|
mod pixel;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
pub mod canonical;
|
pub mod canonical;
|
||||||
|
|
||||||
|
|
23
src/utils.rs
Normal file
23
src/utils.rs
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue