< Summary

Information
Class: NGql.Core.Pooling.LockFreeArgumentsPool
Assembly: NGql.Core
File(s): /home/runner/work/NGql/NGql/src/Core/Pooling/LockFreeArgumentsPool.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 44
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%11100%
GetPooled(...)100%22100%
Return(...)100%11100%
.ctor(...)100%11100%
Dispose()100%11100%

File(s)

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

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2
 3namespace NGql.Core.Pooling;
 4
 5/// <summary>
 6/// Lock-free pool for SortedDictionary arguments with thread-local optimization to eliminate contention
 7/// </summary>
 8internal static class LockFreeArgumentsPool
 9{
 310    private static readonly ThreadLocalPool<SortedDictionary<string, object?>> _pool = new(
 1211        factory: () => new SortedDictionary<string, object?>(StringComparer.OrdinalIgnoreCase),
 2712        reset: dict => dict.Clear(),
 313        poolName: "arguments"
 314    );
 15
 16    /// <summary>
 17    /// Gets a pooled dictionary populated from source
 18    /// </summary>
 19    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 20    internal static PooledArguments GetPooled(Dictionary<string, object?> source)
 21    {
 2722        var dict = _pool.Get();
 8423        foreach (var kvp in source)
 1524            dict[kvp.Key] = kvp.Value;
 2725        return new PooledArguments(dict);
 26    }
 27
 28    /// <summary>
 29    /// Returns dictionary to the pool
 30    /// </summary>
 31    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 32    [System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S3398:Move this method inside 'PooledArguments
 2733    private static void Return(SortedDictionary<string, object?> dict) => _pool.Return(dict);
 34
 35    /// <summary>
 36    /// Zero-allocation ref struct wrapper with lock-free pooling
 37    /// </summary>
 38    internal readonly ref struct PooledArguments
 39    {
 40        public readonly SortedDictionary<string, object?> Dictionary;
 2741        internal PooledArguments(SortedDictionary<string, object?> dictionary) => Dictionary = dictionary;
 2742        public void Dispose() => Return(Dictionary);
 43    }
 44}