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

Prefer use of interpolated strings in PresentationCore #8616

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

Conversation

halgab
Copy link
Contributor

@halgab halgab commented Dec 30, 2023

Follow-up to #8519

Description

We replace as many manual string concatenations and string.Format with interpolated strings. This saves allocations in many instances, and makes for a more readable code.

Customer Impact

Less allocations

Regression

No

Testing

CI

Risk

Low. Most changes are automated using the IDE

Microsoft Reviewers: Open in CodeFlow

@ghost ghost assigned halgab Dec 30, 2023
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Dec 30, 2023
@ghost ghost requested review from dipeshmsft and singhashish-wpf December 30, 2023 19:45
@ghost ghost added the Community Contribution A label for all community Contributions label Dec 30, 2023
Comment on lines 58 to +61
#if DEBUG
if (_traceSwitch.Enabled)
System.Diagnostics.Trace.TraceInformation(
DateTime.Now.ToLongTimeString() + " " + DateTime.Now.Millisecond + " " +
Environment.CurrentManagedThreadId +
": SiteOfOriginContainer: returning site of origin " + siteOfOrigin);
$"{DateTime.Now:T} {DateTime.Now.Millisecond} {Environment.CurrentManagedThreadId}: SiteOfOriginContainer: returning site of origin {siteOfOrigin}");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A follow-up to this is to introduce a Trace method with a custom interpolated string handler that encapsulate all this logic. It would clean-up the code quite a lot

Copy link
Contributor

Choose a reason for hiding this comment

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

@halgab Having an encapsulated function would be beneficial for maintaining clean code. Could you please provide the function's arguments and structure that you are considering?

We are planning to add this PR for this month test-pass. So, can you resolve the merge conflicts for this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a draft PR based on this one here: #8702. Its last commit is what I have in mind. It's based on similar changes I contributed in the winforms repo.

@ghost ghost added the draft label Dec 30, 2023
@halgab halgab marked this pull request as ready for review December 30, 2023 21:33
@halgab halgab requested a review from a team as a code owner December 30, 2023 21:33
@halgab halgab changed the title Prefer use interpolated strings in PresentationCore Prefer use of interpolated strings in PresentationCore Dec 30, 2023
@ghost ghost removed the draft label Dec 31, 2023
Copy link
Contributor

Choose a reason for hiding this comment

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

@halgab A DRT(test) is failing on this PR: DrtColorAPI
You can find this test on our public repo: https://github.com/dotnet/wpf-test

I think so the test is failing due to some missing elements in this file after change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After having another read, the difference between the current version and mine is that when nativeColorValue is empty, the current version still appends a separator value, which is not the case with my version. I feel like my version is more correct.
Tell me if you prefer that I maintain the current behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

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

Your changes are functionally different. Floats were formatted using format previously but are now always formatted using R. Also, the loop in your changes always prepends the separator instead of prepending the separator only when between items: ",A,B,C" vs "A,B,C". Also, there should be a space here between {uriString} and {scRgbColor.a:R}, it was there before your changes.

I would recommend testing your changes because by looking at the code I don't see how your changes returns the same result as the existing code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those are valid points. I'll rollback the functional changes. I'd like to keep the constant format though, as format is always set to R before this loop, and that's what makes it possible to use interpolated strings. What do you think?

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

Successfully merging this pull request may close these issues.

None yet

4 participants