diff --git a/Recyclable.Collections/RecyclableList.Helpers.cs b/Recyclable.Collections/RecyclableList.Helpers.cs index 02cfbf0..cde4f4a 100644 --- a/Recyclable.Collections/RecyclableList.Helpers.cs +++ b/Recyclable.Collections/RecyclableList.Helpers.cs @@ -52,10 +52,6 @@ namespace Recyclable.Collections [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static int EnsureCapacity(RecyclableList list, int requestedCapacity) { - // int newCapacity; - // switch (list._capacity > 0) - // { - // case true: int newCapacity = list._capacity; while (newCapacity < requestedCapacity) { @@ -63,39 +59,9 @@ namespace Recyclable.Collections } ResizeAndCopy(list, newCapacity); - // break; - - // case false: - // newCapacity = requestedCapacity; - // list._memoryBlock = Resize(list, newCapacity); - // break; - // } - - // newCapacity = list._memoryBlock.Length; - // list._capacity = newCapacity; return list._capacity; } - [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - public static void EnsureExactCapacity(RecyclableList list, int requestedCapacity) - { - // int newCapacity; - // switch (list._capacity > 0) - // { - // case true: - ResizeAndCopy(list, requestedCapacity); - // break; - - // case false: - // newCapacity = requestedCapacity; - // list._memoryBlock = Resize(list, newCapacity); - // break; - // } - - // var newCapacity = list._memoryBlock.Length; - // list._capacity = list._memoryBlock.Length; - } - [Obsolete("This method WILL be removed in the near future. Please use the existing enumerators instead of it.")] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable Enumerate(RecyclableList arrays, int chunkSize, long totalCount) @@ -257,13 +223,6 @@ namespace Recyclable.Collections return values[middle]; } - // [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - // public static T[] Resize(int newSize) - // // ArrayPool arrayPool = _arrayPool; - // => newSize >= RecyclableDefaults.MinPooledArrayLength - // ? _arrayPool.Rent(newSize) - // : new T[newSize]; - internal static readonly ArrayPool _arrayPool = ArrayPool.Create(); private static readonly bool NeedsClearing = !typeof(T).IsValueType; @@ -271,7 +230,6 @@ namespace Recyclable.Collections [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] public static void ResizeAndCopy(RecyclableList sourceList, int newSize) { - // ArrayPool arrayPool = _arrayPool; T[] newMemoryBlock = newSize >= RecyclableDefaults.MinPooledArrayLength ? _arrayPool.Rent(newSize) : new T[newSize]; @@ -280,7 +238,6 @@ namespace Recyclable.Collections T[] oldMemoryBlock = sourceList._memoryBlock; // & WAS SLOWER AS ARRAY - // new Span(oldMemoryBlock).CopyTo(newMemoryBlock); Array.Copy(oldMemoryBlock, newMemoryBlock, oldMemoryBlock.Length); if (oldMemoryBlock.Length >= RecyclableDefaults.MinPooledArrayLength) @@ -293,49 +250,6 @@ namespace Recyclable.Collections // If anything, it has been already cleared above, so we don't need to repeat it. _arrayPool.Return(oldMemoryBlock, NeedsClearing); - //_arrayPool.Return(oldMemoryBlock, NeedsClearing); - } - - sourceList._memoryBlock = newMemoryBlock; - sourceList._capacity = newMemoryBlock.Length; - } - - [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - public static void ResizeAndCopy(RecyclableList sourceList) - { - // ArrayPool arrayPool = _arrayPool; - // int newSize = _capacity << 1; - if ((sourceList._capacity <<= 1) < RecyclableDefaults.MinPooledArrayLength) - { - Array.Resize(ref sourceList._memoryBlock, sourceList._capacity); - // _capacity <<= 1; - return; - } - - T[] newMemoryBlock = _arrayPool.Rent(sourceList._capacity); - //T[] newMemoryBlock = _arrayPool.Rent(sourceList._capacity); - // T[] newMemoryBlock = newSize >= RecyclableDefaults.MinPooledArrayLength - // ? RecyclableListHelpers._arrayPool.Rent(newSize) - // : new T[newSize]; - - // & WAS SLOWER WITHOUT - T[] oldMemoryBlock = sourceList._memoryBlock; - - // & WAS SLOWER AS ARRAY - new Span(oldMemoryBlock).CopyTo(newMemoryBlock); - // Array.Copy(oldMemoryBlock, newMemoryBlock, oldMemoryBlock.Length); - - if (oldMemoryBlock.Length >= RecyclableDefaults.MinPooledArrayLength) - { - // TODO: Measure gain vs relying on arrayPool to clear - //if (NeedsClearing) - //{ - // Array.Clear(source); - //} - - // If anything, it has been already cleared above, so we don't need to repeat it. - _arrayPool.Return(oldMemoryBlock, NeedsClearing); - //_arrayPool.Return(oldMemoryBlock, NeedsClearing); } sourceList._memoryBlock = newMemoryBlock;