Micro-optimizations for the best performance in BuildDivisorCandidates..

This commit is contained in:
Marek Lemańczyk committed 2025-09-11 19:07:50 +02:00
1 parent 11bd89d8d0
commit 82737b99fd
1 file changed
+5 -6
+5 -6
View File
@@ -916,10 +916,10 @@ internal static class Program
private static (ulong divisor, uint cycle)[] BuildDivisorCandidates()
{
uint[] snapshot = MersenneDivisorCycles.Shared.ExportSmallCyclesSnapshot();
List<(ulong divisor, uint cycle)> list = new(snapshot.Length / 2);
ulong d;
Span<(ulong divisor, uint cycle)> list = stackalloc (ulong divisor, uint cycle)[snapshot.Length / 2];// new(snapshot.Length / 2);
uint cycle;
for (int i = 3; i < snapshot.Length; i += 2)
int count = 0, i, snapshotLength = snapshot.Length;
for (i = 3; i < snapshotLength; i += 2)
{
cycle = snapshot[i];
if (cycle == 0U)
@@ -927,11 +927,10 @@ internal static class Program
continue;
}
d = (ulong)i;
list.Add((d, cycle));
list[count++] = ((ulong)i, cycle);
}
return list.ToArray();
return list[..count].ToArray();
}
private static bool IsDivisible(ulong exponent, ulong divisor)