Skip to content

Commit

Permalink
chore: likely/unlikely does not work on stable
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed May 28, 2024
1 parent fb9482f commit bbcfec4
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,10 @@ pub(crate) fn trim_end_vec<T: PartialEq>(vec: &mut Vec<T>, value: &T) {
#[cfg(feature = "nightly")]
pub(crate) use core::intrinsics::{likely, unlikely};

// On stable we can use #[cold] to get a equivalent effect: this attribute
// suggests that the function is unlikely to be called
#[cfg(not(feature = "nightly"))]
#[inline(always)]
#[cold]
const fn cold() {}

pub(crate) use core::convert::identity as likely;
#[cfg(not(feature = "nightly"))]
#[inline(always)]
pub(crate) const fn likely(b: bool) -> bool {
if !b {
cold();
}
b
}

#[cfg(not(feature = "nightly"))]
#[inline(always)]
pub(crate) const fn unlikely(b: bool) -> bool {
if b {
cold();
}
b
}
pub(crate) use core::convert::identity as unlikely;

#[cfg(test)]
mod tests {
Expand Down

0 comments on commit bbcfec4

Please sign in to comment.