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

Improve assembly of Contiguous derive #200

Merged
merged 1 commit into from
Sep 5, 2023

Conversation

e00E
Copy link
Contributor

@e00E e00E commented Jul 19, 2023

from_integer and into_integer are usually provided by the trait's default implementation. We override this implementation because it goes through transmute_copy, which can lead to inefficient assembly as seen in #175 .

Closes #175

Implemented my suggestion from when I reported the issue. The downside of this approach is that we're duplicating code between the derive and the default implementation. The upside is the better assembly from the derived implementation. It can do better than the default implementation because it has more information.

I changed the range check to contains because Clippy complained about about it and I wanted both version of the function to have the same check.
Edit: Reverted because MSRV doesn't support contains.

I verified that the linked issue is fixed by this PR.

@e00E
Copy link
Contributor Author

e00E commented Jul 19, 2023

I see CI fails because contains isn't stable on the MSRV. Will change it back to manual if.
Edit: done

`from_integer` and `into_integer` are usually provided by the trait's
default implementation. We override this implementation because it goes
through `transmute_copy`, which can lead to inefficient assembly as seen
in Lokathor#175 .
@Lokathor Lokathor added semver-patch semver patch change semver-derive We need to update the main crate's use of the derive crate labels Sep 5, 2023
@Lokathor
Copy link
Owner

Lokathor commented Sep 5, 2023

Sorry this got lost for a while, but it looks great!

@Lokathor Lokathor merged commit 3c1a0d9 into Lokathor:main Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-derive We need to update the main crate's use of the derive crate semver-patch semver patch change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suboptimal assembly for Contiguous derive
2 participants