/// <summary> /// The result from this call is meant to be used in a using. /// </summary> /// <param name="set">A previously borrowed set or null.</param> /// <returns>A newly borrowed set or the same instance with incremented ref count.</returns> #pragma warning disable IDISP015 // Member should not return created and cached instance. public static PooledSet <T> BorrowOrIncrementUsage(PooledSet <T>?set) #pragma warning restore IDISP015 // Member should not return created and cached instance. { if (set is null) { return(Borrow()); } // ReSharper disable once RedundantAssignment var current = Interlocked.Increment(ref set.refCount); Debug.Assert(current >= 1, $"{nameof(BorrowOrIncrementUsage)} set.refCount == {current}"); return(set); }
/// <summary> /// The result from this call is meant to be used in a using. /// </summary> /// <typeparam name="T">The type of items in the set.</typeparam> /// <returns>A <see cref="PooledSet{T}"/>.</returns> public static PooledSet <T> Borrow <T>() => PooledSet <T> .Borrow();
/// <summary> /// The result from this call is meant to be used in a using. /// </summary> /// <typeparam name="T">The type of elements in the set.</typeparam> /// <param name="set">The <see cref="PooledSet{T}"/>.</param> /// <returns>The set with incremented usage or a new set if null was passed.</returns> public static PooledSet <T> IncrementUsage <T>(this PooledSet <T> set) { return(PooledSet <T> .BorrowOrIncrementUsage(set)); }
/// <summary> /// Initializes a new instance of the <see cref="PooledSetDebugView{T}"/> class. /// </summary> /// <param name="set">The set.</param> internal PooledSetDebugView(PooledSet <T> set) { this.set = set ?? throw new ArgumentNullException(nameof(set)); }