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

Use stackalloc in System.Xml.Xsl.Runtime.NumberFormatterBase.ConvertToAlphabetic #67003

Merged
merged 1 commit into from
Mar 24, 2022

Conversation

TrayanZapryanov
Copy link
Contributor

Another usage of new char[7] found and replaced with stackalloc

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Mar 22, 2022
@filipnavara filipnavara removed the community-contribution Indicates that the PR has been added by a community member label Mar 22, 2022
@@ -82,7 +82,7 @@ public static void ConvertToAlphabetic(StringBuilder sb, double val, char firstC
Debug.Assert(1 <= val && val <= MaxAlphabeticValue);
Debug.Assert(Math.Pow(totalChars, MaxAlphabeticLength) >= MaxAlphabeticValue);

char[] letters = new char[MaxAlphabeticLength];
Span<char> letters = stackalloc char[MaxAlphabeticLength];
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to your change, but it'd be nice to use Math.DivRem below.

@@ -93,7 +93,7 @@ public static void ConvertToAlphabetic(StringBuilder sb, double val, char firstC
number = quot;
}
letters[--idx] = (char)(firstChar + --number);
sb.Append(letters, idx, MaxAlphabeticLength - idx);
sb.Append(letters.Slice(idx, MaxAlphabeticLength - idx));
Copy link
Member

Choose a reason for hiding this comment

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

Is the , MaxAlphabeticLength - idx part needed? It couldn't just be sb.Append(letters.Slice(id))?

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 think it is the same , just wanted to keep the code almost the same as before.

@ghost
Copy link

ghost commented Mar 22, 2022

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

Issue Details

Another usage of new char[7] found and replaced with stackalloc

Author: TrayanZapryanov
Assignees: -
Labels:

area-System.Xml

Milestone: -

Copy link
Member

@krwq krwq left a comment

Choose a reason for hiding this comment

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

LGTM I'd recommend to apply changes suggested by @stephentoub, please let me know if you plan to leave as is

@TrayanZapryanov
Copy link
Contributor Author

@krwq I don't feel comfortable to change logic here as I cannot find a proper tests for this methods.
By using reference in VS I reached System.Xml.Xsl.Xslt.QilGenerator which might use this functionality but how/whether it has tests ....
If you point me to some tests that run through this method - I would be happy to try resolving comments.

@krwq
Copy link
Member

krwq commented Mar 24, 2022

@TrayanZapryanov I'll merge as is in that case. If you feel like making the change feel free to create follow up PR. For the tests I'm currently not sure - I'd probably put a breakpoint in that code path and start running all tests and see the stacktrace. Optionally just always throw an exception from that method and see which tests fail.

@krwq krwq merged commit 9836d5a into dotnet:main Mar 24, 2022
@TrayanZapryanov TrayanZapryanov deleted the numberformater_stackalloc branch March 24, 2022 17:11
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Mar 30, 2022
Co-authored-by: Trayan Zapryanov <Traian.Zaprianov@docuware.com>
@ghost ghost locked as resolved and limited conversation to collaborators Apr 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.

4 participants