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