PartialFactorPendingEntry changed back to struct for better performance.
This commit is contained in:
1 parent
a185149eba
commit
96bb6a4340
2 files changed
+8
-37
No files matched your search
@@ -2,37 +2,9 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace PerfectNumbers.Core;
|
||||
|
||||
public sealed class PartialFactorPendingEntry(ulong value, bool knownComposite)
|
||||
public struct PartialFactorPendingEntry(ulong value, bool knownComposite)
|
||||
{
|
||||
[ThreadStatic]
|
||||
private static PartialFactorPendingEntry? _poolHead;
|
||||
private PartialFactorPendingEntry? _next;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static PartialFactorPendingEntry Rent(ulong value, bool knownComposite)
|
||||
{
|
||||
var poolHead = _poolHead;
|
||||
if (poolHead == null)
|
||||
{
|
||||
return new(value, knownComposite);
|
||||
}
|
||||
|
||||
_poolHead = poolHead._next;
|
||||
poolHead.Value = value;
|
||||
poolHead.KnownComposite = knownComposite;
|
||||
poolHead.HasKnownPrimality = knownComposite;
|
||||
poolHead.IsPrime = false;
|
||||
return poolHead;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static void Return(PartialFactorPendingEntry entry)
|
||||
{
|
||||
entry._next = _poolHead;
|
||||
_poolHead = entry;
|
||||
}
|
||||
|
||||
public ulong Value = value;
|
||||
public readonly ulong Value = value;
|
||||
public bool KnownComposite = knownComposite;
|
||||
public bool HasKnownPrimality = knownComposite;
|
||||
public bool IsPrime = false;
|
||||
|
||||
Reference in new issue
Block a user