-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add readonly to members in Rect #10156
base: main
Are you sure you want to change the base?
Conversation
This allows making the fields private, which will allow making relevant members readonly for perf.
This allows the compiler to generate more optimized code.
Point, Size, Int32Rect, and Vector would benefit from the same treatment. All structs would, but commonly used ones will have more impact. I'll create these when I get the time, or if someone else feels compelled, ping me. :) |
One would think that compiler could figure out that |
It might. I haven't looked at this particular case. One could get a reasonable indication by looking at sharplab.io. In any case, better to be explicit. :) |
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.
What's the reasoning behind removing the generated Rect, is the plan to remove more generated code ? WpfGfx currently has knowledge of Rect and is the source of truth regarding it's definition, I'm not sure if moving the source of truth to PresentationCore and separate from WpfGfx is a good idea.
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.
I was going to ask about that too, and the process that generates them, does it get regenerated?
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.
It gets generated by MilCodeGen which needs to be ran manually (Though right now we can't run it since it's been broken since WPF was open sourced but it should be fixed by #6135).
I believe the entry that generates this file is this:
<Generate Name="Rect" ManagedClass="true" ManagedValueMethods="true" ManagedTypeConverter="true" NativeRetriever="true" AnimationResource="true"/> |
Marking members as
readonly
allows the compiler to generate more efficient code.https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/struct#readonly-instance-members
This is in two commits. The first collapses code into a single file and the second adds the
readonly
. Suggest looking at the second commit for the diff and do not squash the commits.Microsoft Reviewers: Open in CodeFlow