diff --git a/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableList.cs b/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableList.cs index 4bf6795..b661bc2 100644 --- a/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableList.cs +++ b/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableList.cs @@ -14,7 +14,7 @@ namespace Recyclable.Collections.Benchmarks [Benchmark] public void RecyclableList_Create_WithCapacity() { - using var list = new RecyclableList(blockSize: 102_400, expectedItemsCount: TestObjectCount); + using var list = new RecyclableList(minBlockSize: 102_400, expectedItemsCount: TestObjectCount); DoNothing(list); } @@ -35,7 +35,7 @@ namespace Recyclable.Collections.Benchmarks { var data = TestObjects; var dataCount = TestObjectCount; - using var list = new RecyclableList(blockSize: 102_400, expectedItemsCount: dataCount); + using var list = new RecyclableList(minBlockSize: 102_400, expectedItemsCount: dataCount); for (var i = 0; i < dataCount; i++) { list.Add(data[i]); diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index 68dfce5..9566f90 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -74,11 +74,11 @@ namespace Recyclable.Collections } [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected static T[][] SetNewLength(in T[][]? source, int blockSize, in long newCapacity) + protected static T[][] SetNewLength(in T[][]? source, int minBlockSize, in long newCapacity) { ArrayPool arrayPool = _arrayPool; var sourceBlockCount = source?.Length ?? 0; - int requiredBlockCount = (int)(newCapacity / blockSize) + (newCapacity % blockSize > 0 ? 1 : 0); + int requiredBlockCount = (int)(newCapacity / minBlockSize) + (newCapacity % minBlockSize > 0 ? 1 : 0); T[][] newMemoryBlocks = requiredBlockCount < RecyclableDefaults.MinPooledArrayLength ? new T[requiredBlockCount][] @@ -101,32 +101,32 @@ namespace Recyclable.Collections int uninitializedBlocksCount = newMemoryBlocksSpan.Length; if (uninitializedBlocksCount == requiredBlockCount) { - if (blockSize >= RecyclableDefaults.MinPooledArrayLength) + if (minBlockSize >= RecyclableDefaults.MinPooledArrayLength) { - newMemoryBlocksSpan[0] = blockArrayPool.Rent(blockSize); - blockSize = newMemoryBlocksSpan[0].Length; + newMemoryBlocksSpan[0] = blockArrayPool.Rent(minBlockSize); + minBlockSize = newMemoryBlocksSpan[0].Length; } else { - newMemoryBlocksSpan[0] = new T[blockSize]; + newMemoryBlocksSpan[0] = new T[minBlockSize]; } newMemoryBlocksSpan = newMemoryBlocksSpan[1..]; uninitializedBlocksCount--; } - if (blockSize >= RecyclableDefaults.MinPooledArrayLength) + if (minBlockSize >= RecyclableDefaults.MinPooledArrayLength) { for (int i = 0; i < uninitializedBlocksCount; i++) { - newMemoryBlocksSpan[i] = blockArrayPool.Rent(blockSize); + newMemoryBlocksSpan[i] = blockArrayPool.Rent(minBlockSize); } } else { for (int i = 0; i < uninitializedBlocksCount; i++) { - newMemoryBlocksSpan[i] = new T[blockSize]; + newMemoryBlocksSpan[i] = new T[minBlockSize]; } } @@ -163,42 +163,42 @@ namespace Recyclable.Collections return newCapacity; } - public RecyclableList(int blockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default) + public RecyclableList(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default) { if (expectedItemsCount > 0) { - _memoryBlocks = SetNewLength(_memoryBlocks, blockSize, expectedItemsCount.Value); + _memoryBlocks = SetNewLength(_memoryBlocks, minBlockSize, expectedItemsCount.Value); if (_memoryBlocks.Length > 0) { - blockSize = _memoryBlocks[0].Length; + minBlockSize = _memoryBlocks[0].Length; } - _blockSize = blockSize; - _capacity = _memoryBlocks.Length * blockSize; + _blockSize = minBlockSize; + _capacity = _memoryBlocks.Length * minBlockSize; } else { - _blockSize = blockSize; + _blockSize = minBlockSize; _memoryBlocks = _emptyMemoryBlocksArray; } } - public RecyclableList(IEnumerable source, int blockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default) + public RecyclableList(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default) { if (expectedItemsCount > 0) { - _memoryBlocks = SetNewLength(_memoryBlocks, blockSize, expectedItemsCount.Value); + _memoryBlocks = SetNewLength(_memoryBlocks, minBlockSize, expectedItemsCount.Value); if (_memoryBlocks.Length > 0) { - blockSize = _memoryBlocks[0].Length; + minBlockSize = _memoryBlocks[0].Length; } - _blockSize = blockSize; - _capacity = _memoryBlocks.Length * blockSize; + _blockSize = minBlockSize; + _capacity = _memoryBlocks.Length * minBlockSize; } else { - _blockSize = blockSize; + _blockSize = minBlockSize; _memoryBlocks = _emptyMemoryBlocksArray; }