From a21f6e1c0c66270018d774fa0f9e7f6a24f5732b Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Wed, 17 Jan 2024 23:53:49 +0100 Subject: [PATCH] Failing RecyclableLongList.Compatibility.List.GetRange() cases fixed. --- .../RecyclableLongList.Compatibility.List.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Recyclable.Collections.Compatibility.List/RecyclableLongList.Compatibility.List.cs b/Recyclable.Collections.Compatibility.List/RecyclableLongList.Compatibility.List.cs index d52303f..60055dc 100644 --- a/Recyclable.Collections.Compatibility.List/RecyclableLongList.Compatibility.List.cs +++ b/Recyclable.Collections.Compatibility.List/RecyclableLongList.Compatibility.List.cs @@ -395,7 +395,7 @@ namespace Recyclable.Collections RecyclableLongList result = new(minBlockSize: blockSize, initialCapacity: count); ReadOnlySpan sourceMemoryBlocksSpan = new (list._memoryBlocks), targetMemoryBlocksSpan = new (result._memoryBlocks); - ReadOnlySpan sourceMemoryBlockSpan = sourceMemoryBlocksSpan[0]; + ReadOnlySpan sourceMemoryBlockSpan = sourceMemoryBlocksSpan[blockIndex]; Span targetMemoryBlockSpan = new(targetMemoryBlocksSpan[0]); while (blockIndex < lastBlockWithData) { @@ -439,6 +439,11 @@ namespace Recyclable.Collections while (itemIndex < lastBlockWithData) { targetMemoryBlockSpan[targetItemIndex] = sourceMemoryBlockSpan[itemIndex]; + if (itemIndex + 1 == lastBlockWithData) + { + break; + } + itemIndex++; if (targetItemIndex + 1 == blockSize) { @@ -456,9 +461,9 @@ namespace Recyclable.Collections } } - result._lastBlockWithData = lastBlockWithData; - result._longCount = count; result._nextItemIndex = count & list._blockSizeMinus1; + result._lastBlockWithData = result._nextItemIndex > 0 ? targetBlockIndex : targetBlockIndex - 1; + result._longCount = count; result._nextItemBlockIndex = targetBlockIndex; return result; }