Skip to content

Commit

Permalink
Merge pull request #375 from DaniPopes/rm-likely
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich authored May 29, 2024
2 parents fb9482f + bbcfec4 commit 7dc999e
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 7dc999e

Please sign in to comment.