YamlDotNet
YamlDotNet copied to clipboard
perf: Optimize regular numbers parse logics
This PR intended to optimize performance for number deserialization by changing Parse to TryParse
method.
It's discussed at https://github.com/aaubry/YamlDotNet/pull/794
Additionally this PR fix double
value deserialization problems that are found on UnitTests.
What's Changes
- Replace existing regular number
Parse
logics withTryParse
method. - Separate
float
/double
parse logics for.NET Framework
. - Add code path for .NET that parse text as
double
, then checks float value ranges. - Add related unit tests (
UnquotedStringTypeDeserialization_RegularNumbers
)
.NET Behavior differences
On .NET Framework. float.Parse((double.MaxValue + 1).ToString())
throw OverflowException
.
But on .NET Core. It returns PosititiveInfinite(∞
).
These behavior differences are described at Single.Parse Method page.
In .NET Core 3.0 and later, values that are too large to represent are rounded to [PositiveInfinity] or NegativeInfinity as required by the IEEE 754 specification. In prior versions, including .NET Framework, parsing a value that was too large to represent resulted in failure.
On current implementation.
Values outside the range of the float
type are converted to -∞
/∞
.
So I've added logics to check float value ranges.