Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: likely/unlikely does not work on stable #375

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading