Redefine GridLength as readonly struct to prevent defensive copies #9905
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Since
GridLength
is immutable by design, we should adjust it toreadonly struct
. This will also prevent defensive copies. It will also improve code quality. This is not a breaking change.IEquatable
functions to save precious code lines and simplify it.0.0
in case ofAuto
but when queried, it is set to1.0
.Customer Impact
Possibly a bit of perf and a clear directive that
GridLength
and all its methods are not adjusting the state of thestruct
.Regression
No.
Testing
Local build, base testing, type creation, etc.
Risk
I do not asses any, since the struct is immutable and this is not a breaking change. It is a change to a public type but such changes have been done previously in runtime, see for example #97421.
Microsoft Reviewers: Open in CodeFlow