Avoid pooling small buffers in CPU divisor pipeline

This commit is contained in:
Marek Lemańczyk committed 2025-10-11 21:17:18 +02:00
1 parent 8e9390bc5e
commit ad22329814
4 files changed
+102 -41

No files matched your search

+7 -2
View File
@@ -1058,7 +1058,10 @@ internal static partial class PrimeOrderCalculator
return PartialFactorResult.Rent(null, cofactor, cofactor == 1UL, 0);
}
FactorEntry[] factors = ThreadLocalArrayPool<FactorEntry>.Shared.Rent(counts.Count);
int dictionaryCount = counts.Count;
FactorEntry[] factors = dictionaryCount >= PerfectNumberConstants.PooledArrayThreshold
? ThreadLocalArrayPool<FactorEntry>.Shared.Rent(dictionaryCount)
: new FactorEntry[dictionaryCount];
int index = 0;
foreach (KeyValuePair<ulong, int> entry in counts)
{
@@ -1092,7 +1095,9 @@ internal static partial class PrimeOrderCalculator
return PartialFactorResult.Rent(null, cofactor, cofactor == 1UL, 0);
}
FactorEntry[] array = ThreadLocalArrayPool<FactorEntry>.Shared.Rent(actualCount);
FactorEntry[] array = actualCount >= PerfectNumberConstants.PooledArrayThreshold
? ThreadLocalArrayPool<FactorEntry>.Shared.Rent(actualCount)
: new FactorEntry[actualCount];
int arrayIndex = 0;
for (int i = 0; i < factorCount; i++)
{