From f66b129f3ac027c31e77b197b3da83df8366fb05 Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sun, 25 Jun 2023 20:45:01 +0200 Subject: [PATCH] RecyclableList marked as sealed. All protected entities made private. Future versions will provide a way to create your own, top performance collections. --- Recyclable.Collections/RecyclableList.cs | 18 +++++++++--------- Recyclable.Collections/RecyclableLongList.cs | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index 962e96c..1807a6c 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -9,21 +9,21 @@ namespace Recyclable.Collections { private static readonly ArrayPool _arrayPool = ArrayPool.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(RecyclableList 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 AddRangeEnumerated(IEnumerable source, int growByCount) + private IEnumerator AddRangeEnumerated(IEnumerable source, int growByCount) { int targetItemIdx = _count; Span memorySpan; @@ -61,7 +61,7 @@ namespace Recyclable.Collections return enumerator; } - protected void AddRangeWithKnownCount(IEnumerable source, int targetItemIdx, int requiredAdditionalCapacity) + private void AddRangeWithKnownCount(IEnumerable 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 arrayPool = _arrayPool; T[] newMemoryBlock = newSize >= RecyclableDefaults.MinPooledArrayLength @@ -100,7 +100,7 @@ namespace Recyclable.Collections } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - protected static int EnsureCapacity(RecyclableList list, int requestedCapacity) + private static int EnsureCapacity(RecyclableList 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)] diff --git a/Recyclable.Collections/RecyclableLongList.cs b/Recyclable.Collections/RecyclableLongList.cs index c345b4f..6588a2e 100644 --- a/Recyclable.Collections/RecyclableLongList.cs +++ b/Recyclable.Collections/RecyclableLongList.cs @@ -8,7 +8,7 @@ using System.Runtime.CompilerServices; namespace Recyclable.Collections { - public partial class RecyclableLongList : IList, IReadOnlyList, IDisposable + public partial sealed class RecyclableLongList : IList, IReadOnlyList, IDisposable { private static readonly ArrayPool _defaultMemoryBlocksPool = ArrayPool.Create(); private static readonly ArrayPool _defaultBlockArrayPool = ArrayPool.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 _memoryBlocksPool; - protected ArrayPool _blockArrayPool; + private ArrayPool _memoryBlocksPool; + private ArrayPool _blockArrayPool; #nullable disable internal T[][] _memoryBlocks; #nullable restore