Stop clearing pooled buffers inside rent helpers
This commit is contained in:
1 parent
7baf3b619f
commit
a226ae10cb
3 files changed
+9
-26
No files matched your search
@@ -322,6 +322,7 @@ public class MersenneDivisorCycles
|
||||
primeOrderFailed = false;
|
||||
}
|
||||
|
||||
factorCounts.Clear();
|
||||
ThreadStaticPools.ReturnFactorCountDictionary(factorCounts);
|
||||
return success;
|
||||
}
|
||||
@@ -339,6 +340,7 @@ public class MersenneDivisorCycles
|
||||
bool success = TryFactorIntoCountsInternal(value, scratch);
|
||||
if (!success)
|
||||
{
|
||||
scratch.Clear();
|
||||
ThreadStaticPools.ReturnFactorScratchDictionary(scratch);
|
||||
return false;
|
||||
}
|
||||
@@ -349,6 +351,7 @@ public class MersenneDivisorCycles
|
||||
AddFactor(counts, pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
scratch.Clear();
|
||||
ThreadStaticPools.ReturnFactorScratchDictionary(scratch);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -521,6 +521,7 @@ internal static partial class PrimeOrderCalculator
|
||||
BuildCandidates(order, factorArray, orderFactors.Count, candidates, capacity);
|
||||
if (candidates.Count == 0)
|
||||
{
|
||||
candidates.Clear();
|
||||
ThreadStaticPools.ReturnUlongList(candidates);
|
||||
return false;
|
||||
}
|
||||
@@ -623,6 +624,7 @@ internal static partial class PrimeOrderCalculator
|
||||
pool.Return(gpuPool, clearArray: false);
|
||||
}
|
||||
|
||||
candidates.Clear();
|
||||
ThreadStaticPools.ReturnUlongList(candidates);
|
||||
ThreadStaticPools.ReturnExponentStepper(powStepper);
|
||||
result = candidate;
|
||||
@@ -637,6 +639,7 @@ internal static partial class PrimeOrderCalculator
|
||||
index += batchSize;
|
||||
}
|
||||
|
||||
candidates.Clear();
|
||||
ThreadStaticPools.ReturnUlongList(candidates);
|
||||
ThreadStaticPools.ReturnExponentStepper(powStepper);
|
||||
// DebugLog("No candidate confirmed");
|
||||
@@ -1030,6 +1033,7 @@ internal static partial class PrimeOrderCalculator
|
||||
}
|
||||
|
||||
factorCount = copyIndex;
|
||||
counts.Clear();
|
||||
ThreadStaticPools.ReturnUlongIntDictionary(counts);
|
||||
counts = null;
|
||||
}
|
||||
@@ -1231,6 +1235,7 @@ internal static partial class PrimeOrderCalculator
|
||||
|
||||
if (counts is not null)
|
||||
{
|
||||
counts.Clear();
|
||||
ThreadStaticPools.ReturnUlongIntDictionary(counts);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,11 +129,6 @@ namespace PerfectNumbers.Core
|
||||
int lastIndex = poolCount - 1;
|
||||
List<ulong> list = pool[lastIndex];
|
||||
pool.RemoveAt(lastIndex);
|
||||
if (list.Count > 0)
|
||||
{
|
||||
list.Clear();
|
||||
}
|
||||
|
||||
if (list.Capacity < capacityHint)
|
||||
{
|
||||
list.Capacity = capacityHint;
|
||||
@@ -174,11 +169,6 @@ namespace PerfectNumbers.Core
|
||||
int lastIndex = poolCount - 1;
|
||||
List<PrimeOrderCalculator.PendingEntry> list = pool[lastIndex];
|
||||
pool.RemoveAt(lastIndex);
|
||||
if (list.Count > 0)
|
||||
{
|
||||
list.Clear();
|
||||
}
|
||||
|
||||
if (list.Capacity < capacityHint)
|
||||
{
|
||||
list.Capacity = capacityHint;
|
||||
@@ -219,14 +209,8 @@ namespace PerfectNumbers.Core
|
||||
int lastIndex = poolCount - 1;
|
||||
Stack<ulong> stack = pool[lastIndex];
|
||||
pool.RemoveAt(lastIndex);
|
||||
int stackCount = stack.Count;
|
||||
if (stackCount > 0)
|
||||
{
|
||||
stack.Clear();
|
||||
stackCount = 0;
|
||||
}
|
||||
|
||||
if (stackCount < capacityHint)
|
||||
if (stack.Count < capacityHint)
|
||||
{
|
||||
stack.EnsureCapacity(capacityHint);
|
||||
}
|
||||
@@ -266,11 +250,6 @@ namespace PerfectNumbers.Core
|
||||
int lastIndex = poolCount - 1;
|
||||
Dictionary<ulong, int> dictionary = pool[lastIndex];
|
||||
pool.RemoveAt(lastIndex);
|
||||
if (dictionary.Count > 0)
|
||||
{
|
||||
dictionary.Clear();
|
||||
}
|
||||
|
||||
dictionary.EnsureCapacity(capacityHint);
|
||||
|
||||
return dictionary;
|
||||
@@ -306,14 +285,12 @@ namespace PerfectNumbers.Core
|
||||
}
|
||||
|
||||
_factorCountDictionary = null;
|
||||
dictionary.Clear();
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ReturnFactorCountDictionary(Dictionary<ulong, int> dictionary)
|
||||
{
|
||||
dictionary.Clear();
|
||||
_factorCountDictionary = dictionary;
|
||||
}
|
||||
|
||||
@@ -330,14 +307,12 @@ namespace PerfectNumbers.Core
|
||||
}
|
||||
|
||||
_factorScratchDictionary = null;
|
||||
dictionary.Clear();
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ReturnFactorScratchDictionary(Dictionary<ulong, int> dictionary)
|
||||
{
|
||||
dictionary.Clear();
|
||||
_factorScratchDictionary = dictionary;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user