Crates.io | likely_polyfill |
lib.rs | likely_polyfill |
version | 1.0.0 |
created_at | 2025-08-28 10:45:55.177168+00 |
updated_at | 2025-08-28 10:45:55.177168+00 |
description | cold_path, likely, and unlikely for non-nightly Rust |
homepage | https://docs.rs/likely_polyfill/ |
repository | https://github.com/hsivonen/likely_polyfill |
max_upload_size | |
id | 1813991 |
size | 15,112 |
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.
MIT or Apache-2.0 (since code was copied from the standard library)
There are other pre-existing crates for this purpose, but they use different implementation patterns, and I tested this pattern already.
#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.