-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Avoid unnecessary lazy init in StructuralComparisons #101344
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Some code out there may get broken by
StructuralComparisons.StructuralComparer
implementingIEqualityComparer
orStructuralComparisons.StructuralEqualityComparer
implementingIComparer
. - IL trimmer may end up keeping unusued interface implementation around now that both interfaces are implemented by the same type.
Structural equality is used very rarely, so it is unlikely for these concerns to be a problem in practice. I am mentioning them out of abundance of caution. An alternative would be to keep the two types and add static readonly field in each of the types to get the lazy initialization for free.
I'll switch to that |
Move the fields to the target types and make them readonly instead of manually lazy.
3426e57
to
b7769c4
Compare
* Avoid unnecessary lazy init in StructuralComparisons Move the fields to the target types and make them readonly instead of manually lazy. * Update StructuralComparisons.cs
The only benefit of having these be lazy in this manner is avoiding one of the two objects being constructed. We can instead just combine them into a singleton that's initialized in a static readonly.
Best reviewed without whitespace diff: https://github.com/dotnet/runtime/pull/101344/files?w=1