RecyclableList<T> marked as sealed. All protected entities made private. Future versions will provide a way to create your own, top performance collections.

This commit is contained in:
mlemanczyk committed 2023-06-25 20:45:01 +02:00
1 parent c3820a61d9
commit f66b129f3a
2 files changed
+13 -13

No files matched your search

+9 -9
View File
@@ -9,21 +9,21 @@ namespace Recyclable.Collections
{
private static readonly ArrayPool<T> _arrayPool = ArrayPool<T>.Create();
private static readonly bool _defaultIsNull = default(T) == null;
protected static readonly bool NeedsClearing = !typeof(T).IsValueType;
private static readonly bool NeedsClearing = !typeof(T).IsValueType;
public static explicit operator ReadOnlySpan<T>(RecyclableList<T> source) => new(source._memoryBlock, 0, source.Count);
#nullable disable
protected T[] _memoryBlock;
private T[] _memoryBlock;
#nullable restore
// & WAS SLOWER
// internal RecyclableCollectionVersion _version;
// public RecyclableCollectionVersion Version => _version;
protected ulong _version;
private ulong _version;
public ulong Version => _version;
protected IEnumerator<T> AddRangeEnumerated(IEnumerable<T> source, int growByCount)
private IEnumerator<T> AddRangeEnumerated(IEnumerable<T> source, int growByCount)
{
int targetItemIdx = _count;
Span<T> memorySpan;
@@ -61,7 +61,7 @@ namespace Recyclable.Collections
return enumerator;
}
protected void AddRangeWithKnownCount(IEnumerable<T> source, int targetItemIdx, int requiredAdditionalCapacity)
private void AddRangeWithKnownCount(IEnumerable<T> source, int targetItemIdx, int requiredAdditionalCapacity)
{
_ = EnsureCapacity(this, targetItemIdx + requiredAdditionalCapacity);
@@ -75,7 +75,7 @@ namespace Recyclable.Collections
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
protected static T[] Resize(in T[]? source, int newSize)
private static T[] Resize(in T[]? source, int newSize)
{
ArrayPool<T> arrayPool = _arrayPool;
T[] newMemoryBlock = newSize >= RecyclableDefaults.MinPooledArrayLength
@@ -100,7 +100,7 @@ namespace Recyclable.Collections
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
protected static int EnsureCapacity(RecyclableList<T> list, int requestedCapacity)
private static int EnsureCapacity(RecyclableList<T> list, int requestedCapacity)
{
int newCapacity;
switch (list._capacity > 0)
@@ -204,7 +204,7 @@ namespace Recyclable.Collections
}
}
protected int _capacity;
private int _capacity;
public int Capacity
{
get => _capacity;
@@ -219,7 +219,7 @@ namespace Recyclable.Collections
}
}
protected int _count;
private int _count;
public int Count => _count;
//{
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
+4 -4
View File
@@ -8,7 +8,7 @@ using System.Runtime.CompilerServices;
namespace Recyclable.Collections
{
public partial class RecyclableLongList<T> : IList<T>, IReadOnlyList<T>, IDisposable
public partial sealed class RecyclableLongList<T> : IList<T>, IReadOnlyList<T>, IDisposable
{
private static readonly ArrayPool<T[]> _defaultMemoryBlocksPool = ArrayPool<T[]>.Create();
private static readonly ArrayPool<T> _defaultBlockArrayPool = ArrayPool<T>.Create();
@@ -25,10 +25,10 @@ namespace Recyclable.Collections
internal int _nextItemIndex;
private int _reservedBlockCount;
protected static readonly bool NeedsClearing = !typeof(T).IsValueType;
private static readonly bool NeedsClearing = !typeof(T).IsValueType;
protected ArrayPool<T[]> _memoryBlocksPool;
protected ArrayPool<T> _blockArrayPool;
private ArrayPool<T[]> _memoryBlocksPool;
private ArrayPool<T> _blockArrayPool;
#nullable disable
internal T[][] _memoryBlocks;
#nullable restore