From 1540d8e28659c0a798c22669e6f81f96ce1b653f Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sat, 15 Jul 2023 15:45:09 +0200 Subject: [PATCH] Fixed problem in RecyclableList.Helpers & RecyclableList causing an exception trying to copy too many items into the destination. --- Recyclable.Collections/RecyclableList.Helpers.cs | 4 ++-- Recyclable.Collections/RecyclableList.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Recyclable.Collections/RecyclableList.Helpers.cs b/Recyclable.Collections/RecyclableList.Helpers.cs index 47d324e..4064e99 100644 --- a/Recyclable.Collections/RecyclableList.Helpers.cs +++ b/Recyclable.Collections/RecyclableList.Helpers.cs @@ -237,7 +237,7 @@ namespace Recyclable.Collections : RecyclableArrayPool.Rent(list._capacity); // & WAS SLOWER WITHOUT - new Span(oldMemoryBlock).CopyTo(list._memoryBlock); + new Span(oldMemoryBlock, 0, list._count).CopyTo(list._memoryBlock); if (oldMemoryBlock.Length >= RecyclableDefaults.MinPooledArrayLength) { @@ -266,7 +266,7 @@ namespace Recyclable.Collections T[] oldMemoryBlock = sourceList._memoryBlock; // & WAS SLOWER AS ARRAY - new Span(oldMemoryBlock).CopyTo(newMemoryBlock); + new Span(oldMemoryBlock, 0, sourceList._count).CopyTo(newMemoryBlock); if (oldMemoryBlock.Length >= RecyclableDefaults.MinPooledArrayLength) { diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index 00cd370..b6617fd 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -261,7 +261,7 @@ namespace Recyclable.Collections _ = RecyclableListHelpers.EnsureCapacity(this, targetCapacity); } - new Span(items._memoryBlock).CopyTo(new Span(_memoryBlock, _count, items._count)); + new Span(items._memoryBlock, 0, items._count).CopyTo(new Span(_memoryBlock, _count, items._count)); _count = targetCapacity; _version++; }