-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Reduce allocations in XmlWriterApiTests.TCFullEndElement #112688
Conversation
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.
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 = "";
src/libraries/System.Private.Xml/tests/Writers/XmlWriterApi/TCFullEndElement.cs
Outdated
Show resolved
Hide resolved
Tagging subscribers to this area: @dotnet/area-system-xml |
for (int i = 0; i < strBase64Len; i++) | ||
{ | ||
strBase64 += "A"; | ||
strBase64Builder.Append("A"); |
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.
should this be new string('A', strBase64Len)
instead?
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.
Thanks, forgot about this overload.
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.
LGTM apart from Egor's suggestion.
int charCount = (int)('\ufffe' - '\ue000'); | ||
StringBuilder uniStrBuilder = new StringBuilder(charCount); | ||
|
||
for (char ch = '\ue000'; ch < '\ufffe'; ch++) |
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.
nitpick: extract the chars to make it a bit more readable:
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++) |
* Reduce allocations in XmlWriterApiTests * Apply code review improvements
Attempt to improve #110090 without disabling tests.