Add EnsureCapacity method

This commit is contained in:
Marek Lemańczyk committed 2025-07-10 12:03:34 +02:00
1 parent c3205debed
commit 877b363381
1 file changed
+16
+16
View File
@@ -209,6 +209,22 @@ namespace Recyclable.Collections
}
}
/// <summary>
/// Ensures that the capacity of this list is at least the specified value.
/// </summary>
/// <param name="capacity">The minimum capacity to ensure.</param>
/// <returns>The new capacity of the list.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int EnsureCapacity(int capacity)
{
if (capacity > _capacity)
{
_capacity = RecyclableListHelpers<T>.EnsureCapacity(this, _count, checked((int)BitOperations.RoundUpToPowerOf2((uint)capacity)));
}
return _capacity;
}
public bool IsReadOnly => false;
[MethodImpl(MethodImplOptions.AggressiveInlining)]