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

BigInteger parsing optimizations #47842

Merged
merged 4 commits into from
May 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,8 @@ public static BigInteger Parse(string value, IFormatProvider? provider)

public static BigInteger Parse(string value, NumberStyles style, IFormatProvider? provider)
{
return BigNumber.ParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider));
(int sign, uint[]? bits) = BigNumber.ParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider));
return new BigInteger(sign, bits);
}

public static bool TryParse([NotNullWhen(true)] string? value, out BigInteger result)
Expand All @@ -693,22 +694,31 @@ public static bool TryParse([NotNullWhen(true)] string? value, out BigInteger re

public static bool TryParse([NotNullWhen(true)] string? value, NumberStyles style, IFormatProvider? provider, out BigInteger result)
{
return BigNumber.TryParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider), out result);
bool success = BigNumber.TryParseBigInteger(
value, style, NumberFormatInfo.GetInstance(provider), out int sign, out uint[]? bits);

result = new BigInteger(sign, bits);
jeffhandley marked this conversation as resolved.
Show resolved Hide resolved
return success;
}

public static BigInteger Parse(ReadOnlySpan<char> value, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null)
{
return BigNumber.ParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider));
(int sign, uint[]? bits) = BigNumber.ParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider));
return new BigInteger(sign, bits);
}

public static bool TryParse(ReadOnlySpan<char> value, out BigInteger result)
{
return BigNumber.TryParseBigInteger(value, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
return TryParse(value, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
}

public static bool TryParse(ReadOnlySpan<char> value, NumberStyles style, IFormatProvider? provider, out BigInteger result)
{
return BigNumber.TryParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider), out result);
bool success = BigNumber.TryParseBigInteger(
value, style, NumberFormatInfo.GetInstance(provider), out int sign, out uint[]? bits);
tannergooding marked this conversation as resolved.
Show resolved Hide resolved

result = new BigInteger(sign, bits);
return success;
}

public static int Compare(BigInteger left, BigInteger right)
Expand Down
Loading