< Summary

Information
Class: NGql.Core.Pooling.LockFreeHashSetPool
Assembly: NGql.Core
File(s): /home/runner/work/NGql/NGql/src/Core/Pooling/LockFreeHashSetPool.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 42
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%22100%
GetPooled()100%11100%
Return(...)100%11100%
.ctor(...)100%11100%
Dispose()100%11100%

File(s)

/home/runner/work/NGql/NGql/src/Core/Pooling/LockFreeHashSetPool.cs

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2
 3namespace NGql.Core.Pooling;
 4
 5/// <summary>
 6/// Lock-free pool for HashSet&lt;string&gt; instances with thread-local optimization
 7/// </summary>
 8internal static class LockFreeHashSetPool
 9{
 10    private const int MaxSize = 128; // Prevent memory bloat from large sets
 11    private const int MaxCapacity = 256;
 12
 313    private static readonly ThreadLocalPool<HashSet<string>> _pool = new(
 2514        factory: () => new HashSet<string>(StringComparer.OrdinalIgnoreCase),
 4815        reset: set => set.Clear(),
 5716        validateForReturn: set => set.Count <= MaxSize && set.EnsureCapacity(0) <= MaxCapacity,
 317        poolName: "hashset"
 318    );
 19
 20    /// <summary>
 21    /// Gets an empty pooled HashSet (for warmup/testing)
 22    /// </summary>
 23    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 5724    internal static PooledHashSet GetPooled() => new(_pool.Get());
 25
 26    /// <summary>
 27    /// Returns HashSet to the pool
 28    /// </summary>
 29    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 30    [System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S3398:Move this method inside 'PooledHashSet'"
 5731    private static void Return(HashSet<string> set) => _pool.Return(set);
 32
 33    /// <summary>
 34    /// Zero-allocation ref struct wrapper with lock-free pooling
 35    /// </summary>
 36    internal readonly ref struct PooledHashSet
 37    {
 38        public readonly HashSet<string> Set;
 5739        internal PooledHashSet(HashSet<string> set) => Set = set;
 5740        public void Dispose() => Return(Set);
 41    }
 42}