namespace PerfectNumbers.Core.Cpu; internal struct FactorCacheLease { private Dictionary? _cache; public void EnsureInitialized(ref Dictionary? cache) { Dictionary? current = cache; if (current is null) { current = ThreadStaticPools.RentMersenneFactorCacheDictionary(); cache = current; } _cache = current; } public void Dispose() { Dictionary? cache = _cache; if (cache is null) { return; } ThreadStaticPools.ReturnMersenneFactorCacheDictionary(cache); _cache = null; } }