A crate that brings likely in stable and likelihook for `if let` statement

Yesterday I was somehow frustrated because I could not use core::intrinsics::{likely,unlikely} on stable, and because it was difficult to use those compiler hints for refutable patterns. So I made a crate this morning which is almost a "hackery", to fix that:

  • it takes likely-hood-ness from i32::checked_div and then propagate it to a bool that is then used for branch selection.

  • The macro that provides if_likely{let Some(v) = opt... actually performs the pattern matching twice but this should be cheap I suppose (the compiler optimize out the discriminant double check).

I have checked the assembly. It does work :).

There are details in the documentation obtained by cargo doc --features check_assembly --open => module check_assembly. There is a
demonstration on why #[cold] attribute cannot not be used.

Is there any charitable coder to review the code??

Crate link
repo
doc

7 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.