-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Remove most of string.Trim() usages in System.Private.Xml solution. #75452
Remove most of string.Trim() usages in System.Private.Xml solution. #75452
Conversation
Tagging subscribers to this area: @dotnet/area-system-xml Issue DetailsRemove most of string.Trim() usages in System.Private.Xml solution. Several one left, but it is hard to be replaced as code around them expects string and there is no ReadOnlySpan 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 superficially, although @krwq might want to take a look as well since he's more familiar with the codebase.
src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlValueConverter.cs
Show resolved
Hide resolved
src/libraries/System.Private.Xml/src/System/Xml/Serialization/Xmlcustomformatter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriterHelpers.cs
Show resolved
Hide resolved
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriterHelpers.cs
Show resolved
Hide resolved
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, thanks!
There appear to be |
@eiriktsarpalis Maybe related to #74488 |
@eiriktsarpalis test fail should be connected with issue that I mentioned.
|
@@ -1008,6 +1010,8 @@ public static float ToSingle(string s) | |||
|
|||
public static double ToDouble(string s) | |||
{ | |||
ArgumentNullException.ThrowIfNull(s); |
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.
interestingly this currently throws NRE
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.
@krwq This is to mimic current behavior. Check upper comment which shows difference when using double/float.Parse(string...) and double/float.Parse(ReadOnlySpan...) and passing null.
runtime/src/libraries/System.Private.CoreLib/src/System/Single.cs
Lines 387 to 398 in b40c3a3
public static float Parse(string s, NumberStyles style, IFormatProvider? provider) | |
{ | |
NumberFormatInfo.ValidateParseStyleFloatingPoint(style); | |
if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); | |
return Number.ParseSingle(s, style, NumberFormatInfo.GetInstance(provider)); | |
} | |
public static float Parse(ReadOnlySpan<char> s, NumberStyles style = NumberStyles.Float | NumberStyles.AllowThousands, IFormatProvider? provider = null) | |
{ | |
NumberFormatInfo.ValidateParseStyleFloatingPoint(style); | |
return Number.ParseSingle(s, style, NumberFormatInfo.GetInstance(provider)); | |
} |
Thanks @TrayanZapryanov! Please file an issue on #75452 (comment) if you get a chance |
Remove most of string.Trim() usages in System.Private.Xml solution.
They are replaced with string.AsSpan().Trim(XmlConvert.WhitespaceChars).
If string really contains a space - this will reduce one string allocation.
Several one left, but it is hard to be replaced as code around them expects string and there is no ReadOnlySpan overload.