diff --git a/src/util.rs b/src/util.rs index c8a811732..90a8df311 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,10 +1,34 @@ -// FIXME: Branch prediction hint. This is currently only available on nightly -// but it consistently improves performance by 10-15%. -#[cfg(not(feature = "nightly"))] -pub(crate) use core::convert::{identity as likely, identity as unlikely}; +// FIXME: Replace with `core::hint::{likely, unlikely}` once they are stable. #[cfg(feature = "nightly")] pub(crate) use core::intrinsics::{likely, unlikely}; +#[cfg(not(feature = "nightly"))] +#[inline(always)] +#[cold] +fn cold_path() {} + +#[cfg(not(feature = "nightly"))] +#[inline(always)] +pub(crate) fn likely(b: bool) -> bool { + if b { + true + } else { + cold_path(); + false + } +} + +#[cfg(not(feature = "nightly"))] +#[inline(always)] +pub(crate) fn unlikely(b: bool) -> bool { + if b { + cold_path(); + true + } else { + false + } +} + // FIXME: use strict provenance functions once they are stable. // Implement it with a transmute for now. #[inline(always)]