diff --git a/Recyclable.Collections/RecyclableListExtensions.cs b/Recyclable.Collections/RecyclableListExtensions.cs index e873729..7075a32 100644 --- a/Recyclable.Collections/RecyclableListExtensions.cs +++ b/Recyclable.Collections/RecyclableListExtensions.cs @@ -17,12 +17,12 @@ namespace Recyclable.Collections public static void CopyTo(this T[][] sourceMemoryBlocks, long startingIndex, int blockSize, long itemsCount, T[] destinationArray, int destinationArrayIndex) { - Memory sourceBlockMemory; - Memory destinationArrayMemory; + Span sourceBlockMemory; + Span destinationArrayMemory; int startingBlockIndex = (int)(startingIndex / blockSize); int lastBlockIndex = (int)((itemsCount / blockSize) + (itemsCount - (itemsCount / blockSize) > 0 ? 1 : 0)) - 1; Span sourceMemoryBlocksSpan = new(sourceMemoryBlocks, startingBlockIndex, lastBlockIndex - startingBlockIndex + 1); - destinationArrayMemory = new Memory(destinationArray, destinationArrayIndex, destinationArray.Length); + destinationArrayMemory = new Span(destinationArray, destinationArrayIndex, destinationArray.Length - destinationArrayIndex); int memoryBlockIndex; for (memoryBlockIndex = 0; memoryBlockIndex < lastBlockIndex; memoryBlockIndex++) { @@ -33,7 +33,7 @@ namespace Recyclable.Collections if (itemsCount % blockSize > 0) { - sourceBlockMemory = new(sourceMemoryBlocksSpan[^1], 0, (int)(itemsCount % blockSize)); + sourceBlockMemory = new(sourceMemoryBlocksSpan[lastBlockIndex], 0, (int)(itemsCount % blockSize)); sourceBlockMemory.CopyTo(destinationArrayMemory); } }