Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to optimize Option<R64> ? #38

Open
bestouff opened this issue Oct 20, 2021 · 1 comment
Open

Is there a way to optimize Option<R64> ? #38

bestouff opened this issue Oct 20, 2021 · 1 comment

Comments

@bestouff
Copy link

bestouff commented Oct 20, 2021

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 ?

@Timmmm
Copy link

Timmmm commented Apr 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants