decorum
decorum copied to clipboard
Is there a way to optimize Option<R64> ?
R64 does have some niche values (e.g. Nan values), is it possible to somehow communicate them to the compiler to optimize the size of Option<R64>, so that it's no bigger ?
Rust does it internally for all the NonZero types using
#[rustc_layout_scalar_valid_range_start(1)]
There is also rustc_layout_scalar_valid_range_end(). However these can only be used internally (or maybe on nightly).
So the only way to do it on stable is to use NonZero and add setters/getters that convert the niche value to 0. That's how nonmax works (see this code).
Obviously that has performance implications.
It looks like there is ongoing work on this sort of thing in Rust.