// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Buffers; using System.Collections.Generic; namespace CommunityToolkit.HighPerformance.UnitTests.Buffers.Internals; internal sealed class TrackingArrayPool : ArrayPool { private readonly ArrayPool pool = Create(); private readonly HashSet arrays = new(); /// /// Gets the collection of currently rented out arrays /// public IReadOnlyCollection RentedArrays => this.arrays; /// public override T[] Rent(int minimumLength) { T[] array = this.pool.Rent(minimumLength); _ = this.arrays.Add(array); return array; } /// public override void Return(T[] array, bool clearArray = false) { _ = this.arrays.Remove(array); this.pool.Return(array, clearArray); } }