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