Skip to content

Commit

Permalink
revert to the previous order
Browse files Browse the repository at this point in the history
  • Loading branch information
xtqqczze committed Oct 7, 2024
1 parent f8f7f2d commit dfaf2be
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/libraries/System.Private.CoreLib/src/System/String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,14 @@ public unsafe void CopyTo(int sourceIndex, char[] destination, int destinationIn
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CopyTo(Span<char> destination)
{
if (destination.Length < Length)
if (Length <= destination.Length)
{
Buffer.Memmove(ref destination._reference, ref _firstChar, (uint)Length);
}
else
{
ThrowHelper.ThrowArgumentException_DestinationTooShort();
}

Buffer.Memmove(ref destination._reference, ref _firstChar, (uint)Length);
}

/// <summary>Copies the contents of this string into the destination span.</summary>
Expand All @@ -446,13 +448,13 @@ public void CopyTo(Span<char> destination)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryCopyTo(Span<char> destination)
{
if (destination.Length < Length)
bool retVal = false;
if (Length <= destination.Length)
{
return false;
Buffer.Memmove(ref destination._reference, ref _firstChar, (uint)Length);
retVal = true;
}

Buffer.Memmove(ref destination._reference, ref _firstChar, (uint)Length);
return true;
return retVal;
}

// Returns the entire string as an array of characters.
Expand Down

1 comment on commit dfaf2be

@xtqqczze
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.