1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-13 22:04:09 +02:00

Third time lucky

This is my test code.

var sourceArr = scope int[10] (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
var destArr = scope int[10];
var detSpan = Span<int>(destArr, 0, 5);

sourceArr.CopyTo(detSpan, 2);
// destArr holds 3, 4, 5
This commit is contained in:
Damian Day 2020-05-27 23:33:00 +01:00
parent dd33da0d7c
commit d9c277389e

View file

@ -270,16 +270,18 @@ namespace System
public void CopyTo(Span<T> destination) public void CopyTo(Span<T> destination)
{ {
Debug.Assert(destination.Length >= mLength); Debug.Assert(destination.[Friend]mPtr != null);
Debug.Assert(destination.[Friend]mLength >= mLength);
Internal.MemCpy(destination.Ptr, &GetRef(0), strideof(T) * mLength, alignof(T)); Internal.MemCpy(destination.Ptr, &GetRef(0), strideof(T) * mLength, alignof(T));
} }
public void CopyTo(Span<T> destination, int srcOffset) public void CopyTo(Span<T> destination, int srcOffset)
{ {
Debug.Assert(destination.Length >= mLength); Debug.Assert(destination.[Friend]mPtr != null);
Debug.Assert((uint)srcOffset <= (uint)mLength); Debug.Assert((uint)destination.[Friend]mLength - (uint)srcOffset < (uint)mLength);
Internal.MemCpy(destination.Ptr, &GetRef(srcOffset), strideof(T) * (mLength - srcOffset), alignof(T)); Internal.MemCpy(destination.Ptr, &GetRef(srcOffset), strideof(T) * (destination.Length - srcOffset), alignof(T));
} }
public Span<T>.Enumerator GetEnumerator() public Span<T>.Enumerator GetEnumerator()