Skip to content
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
15 changes: 10 additions & 5 deletions src/libraries/System.Private.CoreLib/src/System/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,18 @@ public static void Copy(Array sourceArray, long sourceIndex, Array destinationAr
Copy(sourceArray, isourceIndex, destinationArray, idestinationIndex, ilength);
}

#if !MONO // implementation details of MethodTable

// Provides a strong exception guarantee - either it succeeds, or
// it throws an exception with no side effects. The arrays must be
// compatible array types based on the array element type - this
// method does not support casting, boxing, or primitive widening.
// It will up-cast, assuming the array types are correct.
public static void ConstrainedCopy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
{
CopyImpl(sourceArray, sourceIndex, destinationArray, destinationIndex, length, reliable: true);
Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length, reliable: true);
}

#if !MONO // implementation details of MethodTable

// Copies length elements from sourceArray, starting at index 0, to
// destinationArray, starting at index 0.
public static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Expand Down Expand Up @@ -396,7 +396,12 @@ public static unsafe void Copy(Array sourceArray, Array destinationArray, int le

// Copies length elements from sourceArray, starting at sourceIndex, to
// destinationArray, starting at destinationIndex.
public static unsafe void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
public static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
{
Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length, reliable: false);
}

private static unsafe void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable)
{
if (sourceArray != null && destinationArray != null)
{
Expand All @@ -423,7 +428,7 @@ public static unsafe void Copy(Array sourceArray, int sourceIndex, Array destina
}

// Less common
CopyImpl(sourceArray, sourceIndex, destinationArray, destinationIndex, length, reliable: false);
CopyImpl(sourceArray, sourceIndex, destinationArray, destinationIndex, length, reliable);
}

// Reliability-wise, this method will either possibly corrupt your
Expand Down
5 changes: 5 additions & 0 deletions src/mono/System.Private.CoreLib/src/System/Array.Mono.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public static void Copy(Array sourceArray, int sourceIndex, Array destinationArr
CopyImpl(sourceArray, sourceIndex, destinationArray, destinationIndex, length, false);
}

public static void ConstrainedCopy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
{
CopyImpl(sourceArray, sourceIndex, destinationArray, destinationIndex, length, true);
}

private static void CopyImpl(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable)
{
ArgumentNullException.ThrowIfNull(sourceArray);
Expand Down
Loading