Merge pull request #1 from mlemanczyk/codex/sprawdz-metody-listt-w-kolekcjach

Add EnsureCapacity to RecyclableList
This commit is contained in:
Marek Lemańczyk authored and GitHub committed 2025-07-10 12:17:35 +02:00
commit 6944fe25b3
4 files changed
+28 -12

No files matched your search

@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>AnyCPU;x64</Platforms>
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
+25 -9
View File
@@ -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;
/// <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)]
public void Add(T item)
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>