Skip to content

Commit

Permalink
keep cast and negate conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
xtqqczze committed Oct 7, 2024
1 parent ea7b629 commit 7242709
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/libraries/System.Private.CoreLib/src/System/String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,12 @@ public unsafe void CopyTo(int sourceIndex, char[] destination, int destinationIn
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CopyTo(Span<char> destination)
{
if (destination.Length >= Length)
{
Buffer.Memmove(ref destination._reference, ref _firstChar, (uint)Length);
}
else
if ((uint)destination.Length < (uint)Length)
{
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 @@ -448,12 +446,13 @@ public void CopyTo(Span<char> destination)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryCopyTo(Span<char> destination)
{
if (destination.Length >= Length)
if ((uint)destination.Length < (uint)Length)
{
Buffer.Memmove(ref destination._reference, ref _firstChar, (uint)Length);
return true;
return false;
}
return false;

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

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

2 comments on commit 7242709

@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.

@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.