revm_primitives/
hints_util.rs

1//! Utility functions for hints.
2//! Used from Hashbrown <https://github.com/rust-lang/hashbrown/blob/0622304393c802aef285257e4864147cc2ac7374/src/util.rs#L12>.
3
4// FIXME: Replace with `core::hint::{likely, unlikely}` once they are stable.
5// pub use core::intrinsics::{likely, unlikely};
6
7/// Cold path function.
8#[inline(always)]
9#[cold]
10pub fn cold_path() {}
11
12/// Returns `b` but mark `false` path as cold
13#[inline(always)]
14pub fn likely(b: bool) -> bool {
15    if b {
16        true
17    } else {
18        cold_path();
19        false
20    }
21}
22
23/// Returns `b` but mark `true` path as cold
24#[inline(always)]
25pub fn unlikely(b: bool) -> bool {
26    if b {
27        cold_path();
28        true
29    } else {
30        false
31    }
32}