Small cleanup
This commit is contained in:
1 parent
9f5871829d
commit
b9933d377b
14 files changed
+33
-44
No files matched your search
@@ -21,7 +21,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
public void RecyclableLongList_AddRangeWhenSourceIsRecyclableLongList()
|
||||
{
|
||||
var data = TestObjectsAsRecyclableList;
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount);
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: BlockSize, initialCapacity: TestObjectCount);
|
||||
list.AddRange(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
{
|
||||
var data = TestObjects;
|
||||
var dataCount = TestObjectCount;
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: BlockSize, expectedItemsCount: dataCount);
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: BlockSize, initialCapacity: dataCount);
|
||||
list.AddRange(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
{
|
||||
var data = TestObjects;
|
||||
var dataCount = TestObjectCount;
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: BlockSize, expectedItemsCount: dataCount);
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: BlockSize, initialCapacity: dataCount);
|
||||
for (var i = 0; i < dataCount; i++)
|
||||
{
|
||||
list.Add(data[i]);
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
|
||||
public void RecyclableLongList_Create_WithCapacity()
|
||||
{
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount);
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: BlockSize, initialCapacity: TestObjectCount);
|
||||
DoNothing(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
public void RecyclableLongList_RemoveAt_FirstItems()
|
||||
{
|
||||
var data = TestObjects;
|
||||
using var list = new RecyclableLongList<long>(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount);
|
||||
using var list = new RecyclableLongList<long>(data, minBlockSize: BlockSize, initialCapacity: base.TestObjectCount);
|
||||
var dataCount = TestObjectCount / 10 > 0 ? TestObjectCount / 10 : TestObjectCount;
|
||||
for (var i = 0; i < dataCount; i++)
|
||||
{
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
public void RecyclableLongList_RemoveAt_LastItems()
|
||||
{
|
||||
var data = TestObjects;
|
||||
using var list = new RecyclableLongList<long>(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount);
|
||||
using var list = new RecyclableLongList<long>(data, minBlockSize: BlockSize, initialCapacity: base.TestObjectCount);
|
||||
var dataCount = TestObjectCount / 10 > 0 ? TestObjectCount / 10 : TestObjectCount;
|
||||
for (var i = data.Length - 1; i > data.Length - dataCount - 1; i--)
|
||||
{
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
public void RecyclableLongList_Remove_FirstItems()
|
||||
{
|
||||
var data = TestObjects;
|
||||
using var list = new RecyclableLongList<long>(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount);
|
||||
using var list = new RecyclableLongList<long>(data, minBlockSize: BlockSize, initialCapacity: base.TestObjectCount);
|
||||
var dataCount = TestObjectCount / 10 > 0 ? TestObjectCount / 10 : TestObjectCount;
|
||||
for (var i = 0; i < dataCount; i++)
|
||||
{
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
public void RecyclableLongList_Remove_LastItems()
|
||||
{
|
||||
var data = TestObjects;
|
||||
using var list = new RecyclableLongList<long>(data, minBlockSize: BlockSize, expectedItemsCount: TestObjectCount);
|
||||
using var list = new RecyclableLongList<long>(data, minBlockSize: BlockSize, initialCapacity:base.TestObjectCount);
|
||||
var dataCount = TestObjectCount / 10 > 0 ? TestObjectCount / 10 : TestObjectCount;
|
||||
for (var i = data.Length - 1; i > data.Length - dataCount - 1; i--)
|
||||
{
|
||||
|
||||
+15
-15
@@ -357,16 +357,16 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
return newCapacity;
|
||||
}
|
||||
|
||||
public RecyclableLongListV1(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool<T[]>? memoryBlocksPool = default, ArrayPool<T>? blockArrayPool = default)
|
||||
public RecyclableLongListV1(int minBlockSize = RecyclableDefaults.BlockSize, long? initialCapacity = default, ArrayPool<T[]>? memoryBlocksPool = default, ArrayPool<T>? blockArrayPool = default)
|
||||
{
|
||||
memoryBlocksPool ??= _defaultMemoryBlocksPool;
|
||||
blockArrayPool ??= _defaultBlockArrayPool;
|
||||
_memoryBlocksPool = memoryBlocksPool;
|
||||
_blockArrayPool = blockArrayPool;
|
||||
|
||||
if (expectedItemsCount > 0)
|
||||
if (initialCapacity > 0)
|
||||
{
|
||||
_capacity = Resize(ref _memoryBlocks, (int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize), 0, expectedItemsCount.Value, memoryBlocksPool, blockArrayPool);
|
||||
_capacity = Resize(ref _memoryBlocks, (int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize), 0, initialCapacity.Value, memoryBlocksPool, blockArrayPool);
|
||||
if (_memoryBlocks!.Length > 0)
|
||||
{
|
||||
minBlockSize = _memoryBlocks[0].Length;
|
||||
@@ -383,16 +383,16 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
}
|
||||
}
|
||||
|
||||
public RecyclableLongListV1(IEnumerable<T> source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool<T[]>? memoryBlocksPool = default, ArrayPool<T>? blockArrayPool = default)
|
||||
public RecyclableLongListV1(IEnumerable<T> source, int minBlockSize = RecyclableDefaults.BlockSize, long? initialCapacity = default, ArrayPool<T[]>? memoryBlocksPool = default, ArrayPool<T>? blockArrayPool = default)
|
||||
{
|
||||
memoryBlocksPool ??= _defaultMemoryBlocksPool;
|
||||
blockArrayPool ??= _defaultBlockArrayPool;
|
||||
_memoryBlocksPool = memoryBlocksPool;
|
||||
_blockArrayPool = blockArrayPool;
|
||||
|
||||
if (expectedItemsCount > 0)
|
||||
if (initialCapacity > 0)
|
||||
{
|
||||
_capacity = Resize(ref _memoryBlocks, (int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize), 0, expectedItemsCount.Value, memoryBlocksPool, blockArrayPool);
|
||||
_capacity = Resize(ref _memoryBlocks, (int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize), 0, initialCapacity.Value, memoryBlocksPool, blockArrayPool);
|
||||
if (_memoryBlocks!.Length > 0)
|
||||
{
|
||||
minBlockSize = _memoryBlocks[0].Length;
|
||||
@@ -1241,16 +1241,16 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
#pragma warning disable CS8618 // It's set by SetupBlockArrayPooling
|
||||
public RecyclableLongListV3(ref OneSizeArrayPool<T> blockArrayPool, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool<T[]>? memoryBlocksPool = default)
|
||||
public RecyclableLongListV3(ref OneSizeArrayPool<T> blockArrayPool, int minBlockSize = RecyclableDefaults.BlockSize, long? initialCapacity = default, ArrayPool<T[]>? memoryBlocksPool = default)
|
||||
#pragma warning restore CS8618
|
||||
{
|
||||
_memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool;
|
||||
|
||||
if (expectedItemsCount > 0)
|
||||
if (initialCapacity > 0)
|
||||
{
|
||||
minBlockSize = checked((int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize));
|
||||
SetupBlockArrayPooling(this, minBlockSize, ref blockArrayPool);
|
||||
_capacity = Resize(this, minBlockSize, _blockSizePow2Shift, expectedItemsCount.Value);
|
||||
_capacity = Resize(this, minBlockSize, _blockSizePow2Shift, initialCapacity.Value);
|
||||
if (_blockSize != _memoryBlocks![0].Length && _capacity > 0)
|
||||
{
|
||||
SetupBlockArrayPooling(this, _memoryBlocks[0].Length, ref blockArrayPool);
|
||||
@@ -1270,15 +1270,15 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618 // It's set by SetupBlockArrayPooling
|
||||
public RecyclableLongListV3(ref OneSizeArrayPool<T> blockArrayPool, IEnumerable<T> source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default, ArrayPool<T[]>? memoryBlocksPool = default)
|
||||
public RecyclableLongListV3(ref OneSizeArrayPool<T> blockArrayPool, IEnumerable<T> source, int minBlockSize = RecyclableDefaults.BlockSize, long? initialCapacity = default, ArrayPool<T[]>? memoryBlocksPool = default)
|
||||
#pragma warning restore CS8618
|
||||
{
|
||||
_memoryBlocksPool = memoryBlocksPool ?? _defaultMemoryBlocksPool;
|
||||
if (expectedItemsCount > 0)
|
||||
if (initialCapacity > 0)
|
||||
{
|
||||
minBlockSize = checked((int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize));
|
||||
SetupBlockArrayPooling(this, minBlockSize, ref blockArrayPool);
|
||||
_capacity = Resize(this, minBlockSize, _blockSizePow2Shift, expectedItemsCount.Value);
|
||||
_capacity = Resize(this, minBlockSize, _blockSizePow2Shift, initialCapacity.Value);
|
||||
if (minBlockSize != _memoryBlocks![0].Length && _capacity > 0)
|
||||
{
|
||||
SetupBlockArrayPooling(this, _memoryBlocks[0].Length, ref blockArrayPool);
|
||||
@@ -1843,19 +1843,19 @@ namespace Recyclable.Collections.Benchmarks.POC
|
||||
{
|
||||
public void RecyclableLongList_EnsureCapacityV1_ByPowOf2()
|
||||
{
|
||||
using var list = new RecyclableLongListV1<long>(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount);
|
||||
using var list = new RecyclableLongListV1<long>(minBlockSize: BlockSize, initialCapacity: TestObjectCount);
|
||||
DoNothing(_ensureCapacityV1Func.Invoke(list, new object[] { TestObjectCount }));
|
||||
}
|
||||
|
||||
public void RecyclableLongList_EnsureCapacityV3_ByPowOf2()
|
||||
{
|
||||
using var list = new RecyclableLongListV3<long>(ref RecyclableArrayPool<long>._pools[BlockSize], minBlockSize: BlockSize, expectedItemsCount: TestObjectCount);
|
||||
using var list = new RecyclableLongListV3<long>(ref RecyclableArrayPool<long>._pools[BlockSize], minBlockSize: BlockSize, initialCapacity: TestObjectCount);
|
||||
DoNothing(_ensureCapacityV3Func.Invoke(null, new object[] { list, TestObjectCount }));
|
||||
}
|
||||
|
||||
public void RecyclableLongList_EnsureCapacity_ByPowOf2()
|
||||
{
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: BlockSize, expectedItemsCount: TestObjectCount);
|
||||
using var list = new RecyclableLongList<long>(minBlockSize: BlockSize, initialCapacity: TestObjectCount);
|
||||
DoNothing(_ensureCapacityNewFunc.Invoke(null, new object[] { list, TestObjectCount }));
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Recyclable.Collections.Benchmarks
|
||||
break;
|
||||
|
||||
case RecyclableCollectionsBenchmarkSource.RecyclableLongList:
|
||||
_testObjectsAsRecyclableLongList ??= new(TestObjects, BlockSize, expectedItemsCount: TestObjectCount);
|
||||
_testObjectsAsRecyclableLongList ??= new(TestObjects, BlockSize, initialCapacity: base.TestObjectCount);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -5,14 +5,6 @@ namespace Recyclable.Collections
|
||||
{
|
||||
internal static class MathUtils
|
||||
{
|
||||
// private static readonly long[] Pow2 = new long[]
|
||||
// {
|
||||
// 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384,
|
||||
// 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304,
|
||||
// 8388608, 16777216, 33554432, 67108864, 134217728, 268435456,
|
||||
// 536870912, 1073741824, 2147483648
|
||||
// };
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsPow2(long value) => (value != 0) && ((value & (value - 1)) == 0);
|
||||
|
||||
|
||||
@@ -124,7 +124,6 @@ namespace Recyclable.Collections
|
||||
// Array.Clear(source);
|
||||
//}
|
||||
|
||||
// // If anything, it has been already cleared above, so we don't need to repeat it.
|
||||
RecyclableArrayPool<T>.ReturnShared(oldMemoryBlock, NeedsClearing);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,8 +344,6 @@ namespace Recyclable.Collections
|
||||
|
||||
return itemIndex >= 0 ? itemIndex + ((long)list._lastBlockWithData << list._blockSizePow2BitShift) : RecyclableDefaults.ItemNotFoundIndexLong;
|
||||
}
|
||||
|
||||
public static int Min(int a, int b, int c) => a < b ? a < c ? a : c : b < c ? b : c;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,14 +167,14 @@ namespace Recyclable.Collections
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
public RecyclableLongList(int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default)
|
||||
public RecyclableLongList(int minBlockSize = RecyclableDefaults.BlockSize, long? initialCapacity = default)
|
||||
{
|
||||
minBlockSize = checked((int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize));
|
||||
|
||||
if (expectedItemsCount > 0)
|
||||
if (initialCapacity > 0)
|
||||
{
|
||||
Helpers.SetupBlockArrayPooling(this, minBlockSize);
|
||||
_capacity = Helpers.Resize(this, minBlockSize, _blockSizePow2BitShift, checked((long)BitOperations.RoundUpToPowerOf2((ulong)expectedItemsCount.Value)));
|
||||
_capacity = Helpers.Resize(this, minBlockSize, _blockSizePow2BitShift, checked((long)BitOperations.RoundUpToPowerOf2((ulong)initialCapacity.Value)));
|
||||
_blockSizeMinus1 = minBlockSize - 1;
|
||||
}
|
||||
else
|
||||
@@ -295,12 +295,12 @@ namespace Recyclable.Collections
|
||||
AddRange(source);
|
||||
}
|
||||
|
||||
public RecyclableLongList(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default)
|
||||
public RecyclableLongList(IEnumerable source, int minBlockSize = RecyclableDefaults.BlockSize, long? initialCapacity = default)
|
||||
{
|
||||
Helpers.SetupBlockArrayPooling(this, minBlockSize = checked((int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize)));
|
||||
if (expectedItemsCount > 0)
|
||||
if (initialCapacity > 0)
|
||||
{
|
||||
_capacity = Helpers.Resize(this, minBlockSize, _blockSizePow2BitShift, checked((int)BitOperations.RoundUpToPowerOf2((uint)expectedItemsCount.Value)));
|
||||
_capacity = Helpers.Resize(this, minBlockSize, _blockSizePow2BitShift, checked((int)BitOperations.RoundUpToPowerOf2((uint)initialCapacity.Value)));
|
||||
_blockSizeMinus1 = minBlockSize - 1;
|
||||
}
|
||||
else
|
||||
@@ -312,12 +312,12 @@ namespace Recyclable.Collections
|
||||
AddRange(source);
|
||||
}
|
||||
|
||||
public RecyclableLongList(IEnumerable<T> source, int minBlockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default)
|
||||
public RecyclableLongList(IEnumerable<T> source, int minBlockSize = RecyclableDefaults.BlockSize, long? initialCapacity = default)
|
||||
{
|
||||
Helpers.SetupBlockArrayPooling(this, minBlockSize = checked((int)BitOperations.RoundUpToPowerOf2((uint)minBlockSize)));
|
||||
if (expectedItemsCount > 0)
|
||||
if (initialCapacity > 0)
|
||||
{
|
||||
_capacity = Helpers.Resize(this, minBlockSize, _blockSizePow2BitShift, checked((int)BitOperations.RoundUpToPowerOf2((uint)expectedItemsCount.Value)));
|
||||
_capacity = Helpers.Resize(this, minBlockSize, _blockSizePow2BitShift, checked((int)BitOperations.RoundUpToPowerOf2((uint)initialCapacity.Value)));
|
||||
_blockSizeMinus1 = minBlockSize - 1;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in new issue
Block a user