RecyclableList.BlockSize enforced to be the power of 2
This commit is contained in:
1 parent
3f986c75a2
commit
b33904a17f
1 file changed
+4
@@ -1,5 +1,6 @@
|
|||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace Recyclable.Collections
|
namespace Recyclable.Collections
|
||||||
@@ -330,6 +331,7 @@ namespace Recyclable.Collections
|
|||||||
blockArrayPool ??= _defaultBlockArrayPool;
|
blockArrayPool ??= _defaultBlockArrayPool;
|
||||||
_memoryBlocksPool = memoryBlocksPool;
|
_memoryBlocksPool = memoryBlocksPool;
|
||||||
_blockArrayPool = blockArrayPool;
|
_blockArrayPool = blockArrayPool;
|
||||||
|
minBlockSize = checked((int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize));
|
||||||
|
|
||||||
if (expectedItemsCount > 0)
|
if (expectedItemsCount > 0)
|
||||||
{
|
{
|
||||||
@@ -357,6 +359,8 @@ namespace Recyclable.Collections
|
|||||||
blockArrayPool ??= _defaultBlockArrayPool;
|
blockArrayPool ??= _defaultBlockArrayPool;
|
||||||
_memoryBlocksPool = memoryBlocksPool;
|
_memoryBlocksPool = memoryBlocksPool;
|
||||||
_blockArrayPool = blockArrayPool;
|
_blockArrayPool = blockArrayPool;
|
||||||
|
minBlockSize = checked((int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize));
|
||||||
|
|
||||||
if (expectedItemsCount > 0)
|
if (expectedItemsCount > 0)
|
||||||
{
|
{
|
||||||
_memoryBlocks = SetNewLength(_memoryBlocks, minBlockSize, 0, expectedItemsCount.Value, memoryBlocksPool, blockArrayPool);
|
_memoryBlocks = SetNewLength(_memoryBlocks, minBlockSize, 0, expectedItemsCount.Value, memoryBlocksPool, blockArrayPool);
|
||||||
|
|||||||
Reference in new issue
Block a user