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

Add readonly to members in Rect #10156

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JeremyKuhne
Copy link
Member

@JeremyKuhne JeremyKuhne commented Dec 10, 2024

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

This allows making the fields private, which will allow making relevant members readonly for perf.
This allows the compiler to generate more optimized code.
@JeremyKuhne JeremyKuhne requested review from a team as code owners December 10, 2024 04:13
@dotnet-policy-service dotnet-policy-service bot added the PR metadata: Label to tag PRs, to facilitate with triage label Dec 10, 2024
@JeremyKuhne
Copy link
Member Author

JeremyKuhne commented Dec 10, 2024

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. :)

@miloush
Copy link
Contributor

miloush commented Dec 10, 2024

One would think that compiler could figure out that double X => _x is readonly...

@JeremyKuhne
Copy link
Member Author

One would think that compiler could figure out that double X => _x is readonly...

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. :)

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants