RecyclableList.AddRange(RecyclableList<T> items) code standardized.

This commit is contained in:
Marek Lemańczyk committed 2023-03-11 20:02:02 +01:00
1 parent fb3290f853
commit e968b47863
1 file changed
+7 -7
+7 -7
View File
@@ -341,10 +341,11 @@ namespace Recyclable.Collections
_lastBlockIndex = targetBlockIndex; _lastBlockIndex = targetBlockIndex;
} }
public void AddRange(in RecyclableList<T> items) public void AddRange(RecyclableList<T> items)
{ {
long itemsCount = items.LongCount; long itemsCount = items.LongCount,
long targetCapacity = _longCount + itemsCount; targetCapacity = _longCount + itemsCount;
if (_capacity < targetCapacity) if (_capacity < targetCapacity)
{ {
_ = EnsureCapacity(targetCapacity); _ = EnsureCapacity(targetCapacity);
@@ -353,11 +354,11 @@ namespace Recyclable.Collections
int blockSize = _blockSize, int blockSize = _blockSize,
sourceBlockIndex = 0, sourceBlockIndex = 0,
targetBlockIndex = _lastBlockIndex, targetBlockIndex = _lastBlockIndex,
toCopy = 0; toCopy;
Span<T[]> sourceMemoryBlocksSpan = new(items._memoryBlocks); Span<T[]> sourceMemoryBlocksSpan = new(items._memoryBlocks, 0, items._memoryBlocks.Length);
Span<T> itemsSpan = new(sourceMemoryBlocksSpan[sourceBlockIndex], 0, items._blockSize); Span<T> itemsSpan = new(sourceMemoryBlocksSpan[sourceBlockIndex], 0, items._blockSize);
Span<T[]> targetMemoryBlocksSpan = new(_memoryBlocks); Span<T[]> targetMemoryBlocksSpan = new(_memoryBlocks, 0, _memoryBlocks.Length);
Span<T> targetBlockArraySpan = new(targetMemoryBlocksSpan[targetBlockIndex], _nextItemIndex, blockSize - _nextItemIndex); Span<T> targetBlockArraySpan = new(targetMemoryBlocksSpan[targetBlockIndex], _nextItemIndex, blockSize - _nextItemIndex);
long copiedCount = 0; long copiedCount = 0;
while (copiedCount < itemsCount) while (copiedCount < itemsCount)
@@ -388,7 +389,6 @@ namespace Recyclable.Collections
{ {
targetBlockIndex++; targetBlockIndex++;
targetBlockArraySpan = new(targetMemoryBlocksSpan[targetBlockIndex]); targetBlockArraySpan = new(targetMemoryBlocksSpan[targetBlockIndex]);
} }
} }
} }