< Summary

Class:Itinero.Routing.Flavours.Dijkstra.SearchPool`1
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Routing/Flavours/Dijkstra/SearchPool.cs
Covered lines:10
Uncovered lines:3
Coverable lines:13
Total lines:37
Line coverage:76.9% (10 of 13)
Covered branches:3
Total branches:4
Branch coverage:75% (3 of 4)
Tag:284_38118444584

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.cctor()100%1100%
Rent()100%2100%
Return(...)50%257.14%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Routing/Flavours/Dijkstra/SearchPool.cs

#LineLine coverage
 1using System.Collections.Concurrent;
 2using System.Threading;
 3
 4namespace Itinero.Routing.Flavours.Dijkstra;
 5
 6/// <summary>
 7/// Reuses search instances so their trees, heaps and visited sets are not rebuilt
 8/// per route. Rented per call and returned in a finally, not [ThreadStatic] — async
 9/// continuations can resume on a thread already running another search.
 10/// </summary>
 11internal static class SearchPool<T> where T : class, new()
 12{
 13    /// Bounds retention: each instance holds buffers sized for its largest search.
 14    private const int MaxRetained = 64;
 15
 216    private static readonly ConcurrentBag<T> Pool = new();
 17    private static int _retained;
 18
 19    public static T Rent()
 1166820    {
 1167121        if (!Pool.TryTake(out var item)) return new T();
 22
 1166523        Interlocked.Decrement(ref _retained);
 1166524        return item;
 1166825    }
 26
 27    public static void Return(T item)
 1166828    {
 1166829        if (Interlocked.Increment(ref _retained) > MaxRetained)
 030        {
 031            Interlocked.Decrement(ref _retained);
 032            return;
 33        }
 34
 1166835        Pool.Add(item);
 1166836    }
 37}

Methods/Properties

.cctor()
Rent()
Return(...)