From 877b363381f81621307147c818585da27f720c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Lema=C5=84czyk?= Date: Thu, 10 Jul 2025 12:03:34 +0200 Subject: [PATCH 1/2] Add EnsureCapacity method --- Recyclable.Collections/RecyclableList.cs | 34 +++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index 4593fd6..db0cfcd 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -190,12 +190,12 @@ namespace Recyclable.Collections } } - internal int _count; - public int Count - { - get => _count; - set - { + internal int _count; + public int Count + { + get => _count; + set + { if (_count != value) { if (value > _capacity) @@ -206,10 +206,26 @@ namespace Recyclable.Collections _count = value; _version++; } - } - } + } + } - public bool IsReadOnly => false; + /// + /// Ensures that the capacity of this list is at least the specified value. + /// + /// The minimum capacity to ensure. + /// The new capacity of the list. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int EnsureCapacity(int capacity) + { + if (capacity > _capacity) + { + _capacity = RecyclableListHelpers.EnsureCapacity(this, _count, checked((int)BitOperations.RoundUpToPowerOf2((uint)capacity))); + } + + return _capacity; + } + + public bool IsReadOnly => false; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(T item) From 29b809cead552b95db59e2d9ecd2067ae49b302f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Lema=C5=84czyk?= Date: Thu, 10 Jul 2025 12:16:48 +0200 Subject: [PATCH 2/2] Add .NET 8 and 9 target frameworks --- .../Recyclable.Collections.Benchmarks.csproj | 2 +- Recyclable.Collections/Recyclable.Collections.csproj | 2 +- Recyclable.CollectionsTests/Recyclable.CollectionsTests.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Recyclable.Collections.Benchmarks/Recyclable.Collections.Benchmarks.csproj b/Recyclable.Collections.Benchmarks/Recyclable.Collections.Benchmarks.csproj index 1bd552a..d27484c 100644 --- a/Recyclable.Collections.Benchmarks/Recyclable.Collections.Benchmarks.csproj +++ b/Recyclable.Collections.Benchmarks/Recyclable.Collections.Benchmarks.csproj @@ -2,7 +2,7 @@ Exe - net6.0;net7.0 + net6.0;net7.0;net8.0;net9.0 enable enable AnyCPU;x64 diff --git a/Recyclable.Collections/Recyclable.Collections.csproj b/Recyclable.Collections/Recyclable.Collections.csproj index 3decd82..bbf75a1 100644 --- a/Recyclable.Collections/Recyclable.Collections.csproj +++ b/Recyclable.Collections/Recyclable.Collections.csproj @@ -1,6 +1,6 @@ - net6.0;net7.0 + net6.0;net7.0;net8.0;net9.0 enable enable true diff --git a/Recyclable.CollectionsTests/Recyclable.CollectionsTests.csproj b/Recyclable.CollectionsTests/Recyclable.CollectionsTests.csproj index 2be9788..398a617 100644 --- a/Recyclable.CollectionsTests/Recyclable.CollectionsTests.csproj +++ b/Recyclable.CollectionsTests/Recyclable.CollectionsTests.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0 + net6.0;net7.0;net8.0;net9.0 enable enable false