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

Undo the Const < (uint)span.Length hacks in the BCL #49450

Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -41,7 +41,7 @@ public static bool TryParse(ReadOnlySpan<byte> source, out bool value, out int b
return true;
}

if (4 < (uint)source.Length)
if (source.Length > 4)
{
if (dw == 0x534c4146 /* 'SLAF' */ && (source[4] & ~0x20) == 'E')
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1208,9 +1208,7 @@ private static bool TryFormatO(DateTime dateTime, TimeSpan offset, Span<char> de
// Tue, 03 Jan 2017 08:08:05 GMT
private static bool TryFormatR(DateTime dateTime, TimeSpan offset, Span<char> destination, out int charsWritten)
{
// Writing the check in this fashion elides all bounds checks on 'destination'
// for the remainder of the method.
if (28 >= (uint)destination.Length)
if (destination.Length <= 28)
{
charsWritten = 0;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private bool InternalFallback(ReadOnlySpan<char> chars, out int charsConsumed)
{
firstChar = chars[0];

if (1 < (uint)chars.Length)
if (chars.Length > 1)
{
secondChar = chars[1];
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public static OperationStatus DecodeFromUtf16(ReadOnlySpan<char> source, out Run
// Let's optimistically assume for now it's a high surrogate and hope
// that combining it with the next char yields useful results.

if (1 < (uint)source.Length)
if (source.Length > 1)
{
char secondChar = source[1];
if (TryCreate(firstChar, secondChar, out result))
Expand Down Expand Up @@ -817,7 +817,7 @@ internal static int ReadFirstRuneFromUtf16Buffer(ReadOnlySpan<char> input)

// Treat 'returnValue' as the high surrogate.

if (1 >= (uint)input.Length)
if (input.Length <= 1)
{
return -1; // not an argument exception - just a "bad data" failure
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static unsafe OperationStatus FromUtf16(ReadOnlySpan<char> source, Span<b

destination = destination.Slice((int)(pOutputBufferRemaining - (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(destination))));

if (2 >= (uint)destination.Length)
if (destination.Length <= 2)
{
operationStatus = OperationStatus.DestinationTooSmall;
break;
Expand Down