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

[derive] Implement an IntoBytes-based PartialEq/Eq derive #2285

Merged
merged 2 commits into from
Feb 3, 2025

Conversation

max-heller
Copy link

The standard library's derive for PartialEq generates a recursive descent into the fields of the type it is applied to. This commit adds a ByteEq derive that generates an optimized, byte-oriented PartialEq implementation -- and a corresponding Eq implementation -- for types that implement IntoBytes. Instead of a recursive descent, the generated implementation performs a single slice comparison of the bytes of the two values being compared.

Closes #2274

The standard library's derive for `PartialEq` generates a recursive
descent into the fields of the type it is applied to. This commit adds
a `ByteEq` derive that generates an optimized, byte-oriented `PartialEq`
implementation -- and a corresponding `Eq` implementation -- for
types that implement `IntoBytes`. Instead of a recursive descent, the
generated implementation performs a single slice comparison of the bytes
of the two values being compared.
@codecov-commenter
Copy link

codecov-commenter commented Feb 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.46%. Comparing base (833f146) to head (d4ce89d).

Additional details and impacted files
@@           Coverage Diff           @@
##           v0.8.x    #2285   +/-   ##
=======================================
  Coverage   87.46%   87.46%           
=======================================
  Files          16       16           
  Lines        6134     6134           
=======================================
  Hits         5365     5365           
  Misses        769      769           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@jswrenn jswrenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jswrenn jswrenn added this pull request to the merge queue Feb 3, 2025
Copy link
Member

@joshlf joshlf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for doing this!

@joshlf joshlf removed this pull request from the merge queue due to a manual request Feb 3, 2025
Co-authored-by: Joshua Liebow-Feeser <[email protected]>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that rustfmt didn't catch this — something to dig into, I think.

@jswrenn jswrenn enabled auto-merge February 3, 2025 21:32
@jswrenn jswrenn added this pull request to the merge queue Feb 3, 2025
Merged via the queue into google:v0.8.x with commit a2f85d3 Feb 3, 2025
87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants