Skip to content

Commit

Permalink
Better stable branch hints
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra authored and Licenser committed Nov 10, 2023
1 parent 8e0b5fe commit c83335a
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,21 +1209,45 @@ macro_rules! unlikely {
}

/// possible compiler hint that a branch is likely
///
/// Technique borrowed from here: <https://github.com/rust-lang/hashbrown/pull/209>
#[cfg(not(feature = "hints"))]
#[macro_export]
macro_rules! likely {
($e:expr) => {
$e
};
($e:expr) => {{
#[inline]
#[cold]
fn cold() {}

let cond = $e;

if !cond {
cold();
}

cond
}};
}

/// possible compiler hint that a branch is unlikely
///
/// Technique borrowed from here: <https://github.com/rust-lang/hashbrown/pull/209>
#[cfg(not(feature = "hints"))]
#[macro_export]
macro_rules! unlikely {
($e:expr) => {
$e
};
($e:expr) => {{
#[inline]
#[cold]
fn cold() {}

let cond = $e;

if cond {
cold();
}

cond
}};
}

/// static cast to an i8
Expand Down

0 comments on commit c83335a

Please sign in to comment.