RecyclableList.AddRange(T[] items) fixed to break the loop when we reach the last block.
This commit is contained in:
1 parent
689061f512
commit
a7d6a9b7e5
1 file changed
+10
-2
@@ -281,15 +281,23 @@ namespace Recyclable.Collections
|
||||
_ = EnsureCapacity(targetCapacity);
|
||||
}
|
||||
|
||||
int blockSize = _blockSize, targetBlockIndex = _lastBlockIndex;
|
||||
int blockSize = _blockSize,
|
||||
targetBlockIndex = _lastBlockIndex,
|
||||
memoryBlockCount = _memoryBlocks.Length;
|
||||
|
||||
Span<T> itemsSpan = new(items);
|
||||
Span<T[]> memoryBlocksSpan = new(_memoryBlocks, 0, _memoryBlocks.Length);
|
||||
Span<T[]> memoryBlocksSpan = new(_memoryBlocks, 0, memoryBlockCount);
|
||||
Span<T> targetBlockArraySpan = new(memoryBlocksSpan[targetBlockIndex], _nextItemIndex, blockSize - _nextItemIndex);
|
||||
while (targetBlockArraySpan.Length <= itemsSpan.Length)
|
||||
{
|
||||
itemsSpan[..targetBlockArraySpan.Length].CopyTo(targetBlockArraySpan);
|
||||
itemsSpan = itemsSpan[targetBlockArraySpan.Length..];
|
||||
targetBlockIndex++;
|
||||
if (targetBlockIndex == memoryBlockCount)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
targetBlockArraySpan = new(memoryBlocksSpan[targetBlockIndex], 0, blockSize);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user