Simplify likely/unlikely/cold helpers
This commit is contained in:
parent
0c8d7c64e8
commit
b25b060945
1 changed files with 10 additions and 14 deletions
24
src/utils.rs
24
src/utils.rs
|
@ -1,23 +1,19 @@
|
|||
#[inline(always)]
|
||||
#[allow(unused)]
|
||||
#[cold]
|
||||
pub const fn cold() {}
|
||||
|
||||
#[inline(always)]
|
||||
pub const fn likely(b: bool) -> bool {
|
||||
// borrowed from `likely_stable` crate
|
||||
#[allow(clippy::needless_bool)]
|
||||
if 1_i32.checked_div(if b { 1 } else { 0 }).is_some() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
if !b {
|
||||
cold()
|
||||
}
|
||||
b
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(unused)]
|
||||
pub const fn unlikely(b: bool) -> bool {
|
||||
// borrowed from `likely_stable` crate
|
||||
#[allow(clippy::needless_bool)]
|
||||
if 1_i32.checked_div(if b { 0 } else { 1 }).is_none() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
if b {
|
||||
cold()
|
||||
}
|
||||
b
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue