From 6fc2a10e2835708bd92847a348613e6a7613f26e Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Fri, 24 Mar 2023 19:02:45 +0100 Subject: [PATCH] RecyclableArrayList fixes to always stay within the no. of items on the list, not the size of memory block. --- Recyclable.Collections/RecyclableArrayList.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Recyclable.Collections/RecyclableArrayList.cs b/Recyclable.Collections/RecyclableArrayList.cs index ce4caee..0d61193 100644 --- a/Recyclable.Collections/RecyclableArrayList.cs +++ b/Recyclable.Collections/RecyclableArrayList.cs @@ -176,7 +176,7 @@ namespace Recyclable.Collections _ = EnsureCapacity(targetCapacity); } - var targetSpan = new Span(_memoryBlock)[_count..]; + var targetSpan = new Span(_memoryBlock, _count, sourceItemsCount); Span itemsSpan = new(items); itemsSpan.CopyTo(targetSpan); _count = targetCapacity; @@ -232,8 +232,8 @@ namespace Recyclable.Collections _ = EnsureCapacity(targetCapacity); } - var targetSpan = new Span(_memoryBlock)[_count..]; - Span itemsSpan = new(items._memoryBlock); + var targetSpan = new Span(_memoryBlock, _count, sourceItemsCount); + Span itemsSpan = new(items._memoryBlock, 0, sourceItemsCount); itemsSpan.CopyTo(targetSpan); _count = targetCapacity; } @@ -390,8 +390,8 @@ namespace Recyclable.Collections public int IndexOf(T itemToFind) { - Span memorySpan = new(_memoryBlock); int itemCount = _count; + Span memorySpan = new(_memoryBlock, 0, itemCount); var equalityComparer = _equalityComparer; for (var itemIdx = 0; itemIdx < itemCount; itemIdx++) { @@ -416,8 +416,8 @@ namespace Recyclable.Collections if (oldCount > 0) { - var sourceSpan = new Span(_memoryBlock)[index..oldCount]; - var targetSpan = new Span(_memoryBlock)[(index + 1)..]; + var sourceSpan = new Span(_memoryBlock, index, oldCount); + var targetSpan = new Span(_memoryBlock, index + 1, oldCount); sourceSpan.CopyTo(targetSpan); }