likely_polyfill 1.0.0

cold_path, likely, and unlikely for non-nightly Rust
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented0 out of 3 items with examples
  • Size
  • Source code size: 14.74 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 511.47 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • hsivonen/likely_polyfill
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hsivonen

As a workaround to their stabilization in the standard library remaining perma-open, this crate provides the cold_path, likely, and unlikely hints built on the #[cold] annotation as copied and pasted from the standard library source.

Licensing

MIT or Apache-2.0 (since code was copied from the standard library)

Why not a pre-existing crate?

There are other pre-existing crates for this purpose, but they use different implementation patterns, and I tested this pattern already.

Why not just #cold?

I saw a case where

if cond1 {
    if cond2 {
        // ..
        break;
    }
}
cold_path();

seemed to optimize differently than

if likely(cond1) {
    if likely(cond2) {
        // ..
        break;
    }
}

so it probably makes sense to experiment.