From c7052e778f06cbd520e08c8cca29e84ed0807c58 Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sun, 26 Mar 2023 23:22:32 +0200 Subject: [PATCH] RecyclableList.SetNewLength fixed to properly initialize the list if the no. of memory blocks from array pool exceeds requested no. --- Recyclable.Collections/RecyclableList.cs | 2 +- Recyclable.CollectionsTests/RecyclableListTestData.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index e9ad370..36588ca 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -257,7 +257,7 @@ namespace Recyclable.Collections } localInts[uninitializedBlocksCount] = newMemoryBlocksSpan.Length; - if (localInts[uninitializedBlocksCount] == localInts[requiredBlockCount]) + if (localInts[uninitializedBlocksCount] >= localInts[requiredBlockCount]) { if (minBlockSize >= RecyclableDefaults.MinPooledArrayLength) { diff --git a/Recyclable.CollectionsTests/RecyclableListTestData.cs b/Recyclable.CollectionsTests/RecyclableListTestData.cs index d1119d0..5f8b179 100644 --- a/Recyclable.CollectionsTests/RecyclableListTestData.cs +++ b/Recyclable.CollectionsTests/RecyclableListTestData.cs @@ -16,12 +16,13 @@ namespace Recyclable.CollectionsTests public static readonly IEnumerable ItemsCountVariants = new long[] { - 0, 1, 2, 3, 10, 16, 32, 64, 128, 256, 333, 512, 1_024, 8_192, 16_384 + 0, 1, 2, 3, 10, 16, 32, 64, 128, 256, 333, 512, 1_024, 8_192, 16_384, + 1_000_000 }; public static readonly IEnumerable BlockSizeVariants = new int[] { - 1, 2, 3, 10, 16, 32, 64, 128, 256, 512, 1_024, 2_048, 4_096, + 1, 2, 4, 8, 10, 16, 32, 64, 128, 256, 512, 1_024, 2_048, 4_096, 8_192, 16_384 };