From b33904a17f76e0838cfe8c828847b9d68aca7118 Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Mon, 27 Mar 2023 01:10:54 +0200 Subject: [PATCH] RecyclableList.BlockSize enforced to be the power of 2 --- Recyclable.Collections/RecyclableList.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index c230043..16c1afc 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -1,5 +1,6 @@ using System.Buffers; using System.Collections; +using System.Numerics; using System.Runtime.CompilerServices; namespace Recyclable.Collections @@ -330,6 +331,7 @@ namespace Recyclable.Collections blockArrayPool ??= _defaultBlockArrayPool; _memoryBlocksPool = memoryBlocksPool; _blockArrayPool = blockArrayPool; + minBlockSize = checked((int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize)); if (expectedItemsCount > 0) { @@ -357,6 +359,8 @@ namespace Recyclable.Collections blockArrayPool ??= _defaultBlockArrayPool; _memoryBlocksPool = memoryBlocksPool; _blockArrayPool = blockArrayPool; + minBlockSize = checked((int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize)); + if (expectedItemsCount > 0) { _memoryBlocks = SetNewLength(_memoryBlocks, minBlockSize, 0, expectedItemsCount.Value, memoryBlocksPool, blockArrayPool);