Skip to content

Commit f66c1c1

Browse files
authored
Unify parsing part of BigInteger with CoreLib (dotnet#85978)
1 parent 563664e commit f66c1c1

File tree

10 files changed

+584
-594
lines changed

10 files changed

+584
-594
lines changed

src/libraries/Common/src/System/Number.Parsing.Common.cs

+378
Large diffs are not rendered by default.

src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems

+6-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,6 @@
580580
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Dragon4.cs" />
581581
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Formatting.cs" />
582582
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Grisu3.cs" />
583-
<Compile Include="$(MSBuildThisFileDirectory)System\Number.NumberBuffer.cs" />
584583
<Compile Include="$(MSBuildThisFileDirectory)System\Number.NumberToFloatingPointBits.cs" />
585584
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Parsing.cs" />
586585
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\BitOperations.cs" />
@@ -1420,6 +1419,12 @@
14201419
<Compile Include="$(CommonPath)System\NotImplemented.cs">
14211420
<Link>Common\System\NotImplemented.cs</Link>
14221421
</Compile>
1422+
<Compile Include="$(CommonPath)System\Number.NumberBuffer.cs">
1423+
<Link>System\Number.NumberBuffer.cs</Link>
1424+
</Compile>
1425+
<Compile Include="$(CommonPath)System\Number.Parsing.Common.cs">
1426+
<Link>System\Number.Parsing.Common.cs</Link>
1427+
</Compile>
14231428
<Compile Include="$(CommonPath)System\Numerics\Crc32ReflectedTable.cs">
14241429
<Link>Common\System\Numerics\Crc32ReflectedTable.cs</Link>
14251430
</Compile>

src/libraries/System.Private.CoreLib/src/System/Number.Parsing.cs

-11
Original file line numberDiff line numberDiff line change
@@ -1361,17 +1361,6 @@ private static bool TrailingZeros<TChar>(ReadOnlySpan<TChar> value, int index)
13611361
return null;
13621362
}
13631363

1364-
private static bool IsWhite(uint ch) => (ch == 0x20) || ((ch - 0x09) <= (0x0D - 0x09));
1365-
1366-
private static bool IsDigit(uint ch) => (ch - '0') <= 9;
1367-
1368-
internal enum ParsingStatus
1369-
{
1370-
OK,
1371-
Failed,
1372-
Overflow
1373-
}
1374-
13751364
[DoesNotReturn]
13761365
internal static void ThrowOverflowOrFormatException<TChar, TInteger>(ParsingStatus status, ReadOnlySpan<TChar> value)
13771366
where TChar : unmanaged, IUtfChar<TChar>

src/libraries/System.Runtime.Numerics/src/System.Runtime.Numerics.csproj

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@
1717
<Compile Include="System\Numerics\BigIntegerCalculator.SquMul.cs" />
1818
<Compile Include="System\Numerics\BigIntegerCalculator.Utils.cs" />
1919
<Compile Include="System\Numerics\BigInteger.cs" />
20-
<Compile Include="System\Numerics\BigNumber.cs" />
20+
<Compile Include="System\Number.BigInteger.cs" />
2121
<Compile Include="System\Numerics\NumericsHelpers.cs" />
2222
<Compile Include="System\Numerics\Complex.cs" />
2323
<Compile Include="System\Globalization\FormatProvider.BigInteger.cs" />
24+
<Compile Include="System\Globalization\FormatProvider.Number.cs" />
2425
<Compile Include="System\Globalization\FormatProvider.NumberBuffer.cs" />
2526
<Compile Include="Properties\InternalsVisibleTo.cs" />
2627
</ItemGroup>
2728

2829
<ItemGroup>
29-
<Compile Include="$(CommonPath)System\Globalization\FormatProvider.Number.cs"
30-
Link="System\Globalization\FormatProvider.Number.cs" />
3130
<Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
3231
Link="CoreLib\System\Text\ValueStringBuilder.cs" />
3332
<Compile Include="$(CommonPath)System\HexConverter.cs"
3433
Link="Common\System\HexConverter.cs" />
34+
<Compile Include="$(CommonPath)System\Number.NumberBuffer.cs"
35+
Link="Common\System\Number.NumberBuffer.cs" />
36+
<Compile Include="$(CommonPath)System\Number.Parsing.Common.cs"
37+
Link="Common\System\Number.Parsing.Common.cs" />
3538
</ItemGroup>
3639

3740
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Security;
54
using System.Text;
65

76
namespace System.Globalization
@@ -32,43 +31,5 @@ internal static void FormatBigInteger(ref ValueStringBuilder sb, int precision,
3231
}
3332
}
3433
}
35-
36-
internal static bool TryStringToBigInteger(
37-
ReadOnlySpan<char> s,
38-
NumberStyles styles,
39-
NumberFormatInfo numberFormatInfo,
40-
StringBuilder receiver, // Receives the decimal digits
41-
out int precision,
42-
out int scale,
43-
out bool sign
44-
)
45-
{
46-
FormatProvider.Number.NumberBuffer numberBuffer = default;
47-
48-
unsafe
49-
{
50-
// Note: because we passed a non-null StringBuilder (receiver) to TryStringToNumber, it streams the digits into
51-
// that instead of numberBuffer.digits. This is quite important since numberBuffer.digits is a fixed-buffer size
52-
// and BigNumbers can have an arbitrary number of digits.
53-
//
54-
// Just in case a bug is ever introduced into TryStringToNumber that violates this, set the pointer that numberBuffer.digits returns
55-
// to something that will AV.
56-
numberBuffer.overrideDigits = (char*)0x1;
57-
}
58-
if (!Number.TryStringToNumber(s, styles, ref numberBuffer, receiver, numberFormatInfo, parseDecimal: false))
59-
{
60-
precision = default(int);
61-
scale = default(int);
62-
sign = default(bool);
63-
return false;
64-
}
65-
else
66-
{
67-
precision = numberBuffer.precision;
68-
scale = numberBuffer.scale;
69-
sign = numberBuffer.sign;
70-
return true;
71-
}
72-
}
7334
}
7435
}

0 commit comments

Comments
 (0)