From d9c277389e06836515cb6ad5dc681246a7488f11 Mon Sep 17 00:00:00 2001 From: Damian Day Date: Wed, 27 May 2020 23:33:00 +0100 Subject: [PATCH] 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(destArr, 0, 5); sourceArr.CopyTo(detSpan, 2); // destArr holds 3, 4, 5 --- BeefLibs/corlib/src/Array.bf | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/BeefLibs/corlib/src/Array.bf b/BeefLibs/corlib/src/Array.bf index a6dc0e86..b4846ec3 100644 --- a/BeefLibs/corlib/src/Array.bf +++ b/BeefLibs/corlib/src/Array.bf @@ -270,16 +270,18 @@ namespace System public void CopyTo(Span 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)); } public void CopyTo(Span destination, int srcOffset) { - Debug.Assert(destination.Length >= mLength); - Debug.Assert((uint)srcOffset <= (uint)mLength); + Debug.Assert(destination.[Friend]mPtr != null); + 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.Enumerator GetEnumerator()