Pools renamed to FixedCapacityPools. Other fixed capacity collections added. Queues, concurrent queues and standard stacks replaced with fixed capacity stacks. MethodImplOptions.AggressiveInlining and .AggressiveOptimization added to simple methods and getters / setters. Variables optimized in few places.

This commit is contained in:
mlemanczyk committed 2025-12-11 21:10:19 +01:00
1 parent 547d43de84
commit 260aa19e44
25 files changed
+1372 -1300

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
using System.Runtime.CompilerServices;
namespace PerfectNumbers.Core
{
public struct UlongArrayPool(int poolCapacity)
{
private readonly ulong[][] _arrays = new ulong[poolCapacity][];
private int _count = 0;
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public ulong[] Rent(int length)
{
int available = _count;
if (available == 0)
{
return new ulong[length];
}
ulong[][] arrays = _arrays;
available--;
_count = available;
ulong[] candidate = arrays[available];
return candidate.Length >= length ? candidate : new ulong[length];
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public void Return(ulong[] array)
{
ulong[][] arrays = _arrays;
int available = _count;
if (available < arrays.Length)
{
arrays[available] = array;
_count = available + 1;
}
}
}
}