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

Reduce allocations in XmlWriterApiTests.TCFullEndElement #112688

Merged
merged 2 commits into from
Feb 19, 2025

Conversation

oroztocil
Copy link
Member

@oroztocil oroztocil commented Feb 19, 2025

Attempt to improve #110090 without disabling tests.

@Copilot Copilot bot review requested due to automatic review settings February 19, 2025 11:14
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/libraries/System.Private.Xml/tests/Writers/XmlWriterApi/TCFullEndElement.cs:6314

  • The variable name 'UniStr' should be renamed to 'uniStr' for consistency with the rest of the code.
string UniStr = "";

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 19, 2025
@oroztocil oroztocil marked this pull request as draft February 19, 2025 11:14
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-xml
See info in area-owners.md if you want to be subscribed.

for (int i = 0; i < strBase64Len; i++)
{
strBase64 += "A";
strBase64Builder.Append("A");
Copy link
Member

Choose a reason for hiding this comment

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

should this be new string('A', strBase64Len) instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, forgot about this overload.

Copy link
Member

@akoeplinger akoeplinger left a comment

Choose a reason for hiding this comment

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

LGTM apart from Egor's suggestion.

Comment on lines 6315 to 6318
int charCount = (int)('\ufffe' - '\ue000');
StringBuilder uniStrBuilder = new StringBuilder(charCount);

for (char ch = '\ue000'; ch < '\ufffe'; ch++)
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: extract the chars to make it a bit more readable:

Suggested change
int charCount = (int)('\ufffe' - '\ue000');
StringBuilder uniStrBuilder = new StringBuilder(charCount);
for (char ch = '\ue000'; ch < '\ufffe'; ch++)
char startChar = '\ue000';
char endChar = '\ufffe';
int charCount = (int)(endChar - startChar);
StringBuilder uniStrBuilder = new StringBuilder(charCount);
for (char ch = startChar; ch < endChar; ch++)

@oroztocil oroztocil marked this pull request as ready for review February 19, 2025 15:35
@akoeplinger akoeplinger merged commit 4dde471 into dotnet:main Feb 19, 2025
23 checks passed
grendello pushed a commit to grendello/runtime that referenced this pull request Feb 19, 2025
* Reduce allocations in XmlWriterApiTests

* Apply code review improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Xml community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants