time/hint.rs
1//! Hints to the compiler that affects how code should be emitted or optimized.
2
3#![allow(dead_code)] // may be used in the future and has minimal overhead
4
5/// Indicate that a given branch is **not** likely to be taken, relatively speaking.
6#[inline(always)]
7#[cold]
8pub(crate) const fn cold_path() {}
9
10/// Indicate that a given condition is likely to be true.
11#[inline(always)]
12pub(crate) const fn likely(b: bool) -> bool {
13 if !b {
14 cold_path();
15 }
16 b
17}
18
19/// Indicate that a given condition is likely to be false.
20#[inline(always)]
21pub(crate) const fn unlikely(b: bool) -> bool {
22 if b {
23 cold_path();
24 }
25 b
26}