Avoid redundant clearing in CPU divisor sessions

This commit is contained in:
Marek Lemańczyk committed 2025-10-23 01:48:02 +02:00
1 parent f672ff520c
commit f0b4cdf6e2
1 file changed
+9 -4
@@ -35,8 +35,14 @@ internal sealed class MersenneCpuDivisorScanSession : IMersenneNumberDivisorByDi
divisorCycle = DivisorCycleCache.Shared.GetCycleLength(divisor); divisorCycle = DivisorCycleCache.Shared.GetCycleLength(divisor);
if (divisorCycle == 0UL) if (divisorCycle == 0UL)
{ {
hits.Clear(); divisorCycle = MersenneDivisorCycles.CalculateCycleLength(
return; divisor,
cachedData,
skipPrimeOrderHeuristic: true);
if (divisorCycle == 0UL)
{
throw new InvalidOperationException($"Failed to compute a cycle for divisor {divisor}.");
}
} }
} }
@@ -45,8 +51,7 @@ internal sealed class MersenneCpuDivisorScanSession : IMersenneNumberDivisorByDi
var exponentStepper = new ExponentRemainderStepper(cachedData); var exponentStepper = new ExponentRemainderStepper(cachedData);
if (!exponentStepper.IsValidModulus) if (!exponentStepper.IsValidModulus)
{ {
hits.Clear(); throw new InvalidOperationException($"Invalid modulus {cachedData.Modulus} for divisor scans.");
return;
} }
var cycleStepper = new CycleRemainderStepper(divisorCycle); var cycleStepper = new CycleRemainderStepper(divisorCycle);