From e968b47863c02af5e96e4b2317fde0f501c9ec64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Lema=C5=84czyk?= Date: Sat, 11 Mar 2023 20:02:02 +0100 Subject: [PATCH] RecyclableList.AddRange(RecyclableList items) code standardized. --- Recyclable.Collections/RecyclableList.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index 2473f63..3c8c682 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -341,10 +341,11 @@ namespace Recyclable.Collections _lastBlockIndex = targetBlockIndex; } - public void AddRange(in RecyclableList items) + public void AddRange(RecyclableList items) { - long itemsCount = items.LongCount; - long targetCapacity = _longCount + itemsCount; + long itemsCount = items.LongCount, + targetCapacity = _longCount + itemsCount; + if (_capacity < targetCapacity) { _ = EnsureCapacity(targetCapacity); @@ -353,11 +354,11 @@ namespace Recyclable.Collections int blockSize = _blockSize, sourceBlockIndex = 0, targetBlockIndex = _lastBlockIndex, - toCopy = 0; + toCopy; - Span sourceMemoryBlocksSpan = new(items._memoryBlocks); + Span sourceMemoryBlocksSpan = new(items._memoryBlocks, 0, items._memoryBlocks.Length); Span itemsSpan = new(sourceMemoryBlocksSpan[sourceBlockIndex], 0, items._blockSize); - Span targetMemoryBlocksSpan = new(_memoryBlocks); + Span targetMemoryBlocksSpan = new(_memoryBlocks, 0, _memoryBlocks.Length); Span targetBlockArraySpan = new(targetMemoryBlocksSpan[targetBlockIndex], _nextItemIndex, blockSize - _nextItemIndex); long copiedCount = 0; while (copiedCount < itemsCount) @@ -388,7 +389,6 @@ namespace Recyclable.Collections { targetBlockIndex++; targetBlockArraySpan = new(targetMemoryBlocksSpan[targetBlockIndex]); - } } }