-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Conversation
@@ -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]; |
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.
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)); |
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.
Is the , MaxAlphabeticLength - idx
part needed? It couldn't just be sb.Append(letters.Slice(id))
?
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.
I think it is the same , just wanted to keep the code almost the same as before.
Tagging subscribers to this area: @dotnet/area-system-xml Issue DetailsAnother usage of new char[7] found and replaced with stackalloc
|
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 I'd recommend to apply changes suggested by @stephentoub, please let me know if you plan to leave as is
@krwq I don't feel comfortable to change logic here as I cannot find a proper tests for this methods. |
@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. |
Co-authored-by: Trayan Zapryanov <Traian.Zaprianov@docuware.com>
Another usage of new char[7] found and replaced with stackalloc