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
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…
Add table
Add a link
Reference in a new issue