Cleanup. Comments & dead code removed.
This commit is contained in:
1 parent
845cf602dd
commit
391c72ee48
1 file changed
-86
@@ -52,10 +52,6 @@ namespace Recyclable.Collections
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public static int EnsureCapacity(RecyclableList<T> list, int requestedCapacity)
|
public static int EnsureCapacity(RecyclableList<T> list, int requestedCapacity)
|
||||||
{
|
{
|
||||||
// int newCapacity;
|
|
||||||
// switch (list._capacity > 0)
|
|
||||||
// {
|
|
||||||
// case true:
|
|
||||||
int newCapacity = list._capacity;
|
int newCapacity = list._capacity;
|
||||||
while (newCapacity < requestedCapacity)
|
while (newCapacity < requestedCapacity)
|
||||||
{
|
{
|
||||||
@@ -63,39 +59,9 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResizeAndCopy(list, newCapacity);
|
ResizeAndCopy(list, newCapacity);
|
||||||
// break;
|
|
||||||
|
|
||||||
// case false:
|
|
||||||
// newCapacity = requestedCapacity;
|
|
||||||
// list._memoryBlock = Resize(list, newCapacity);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// newCapacity = list._memoryBlock.Length;
|
|
||||||
// list._capacity = newCapacity;
|
|
||||||
return list._capacity;
|
return list._capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
|
||||||
public static void EnsureExactCapacity(RecyclableList<T> 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.")]
|
[Obsolete("This method WILL be removed in the near future. Please use the existing enumerators instead of it.")]
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static IEnumerable<T> Enumerate(RecyclableList<T[]> arrays, int chunkSize, long totalCount)
|
public static IEnumerable<T> Enumerate(RecyclableList<T[]> arrays, int chunkSize, long totalCount)
|
||||||
@@ -257,13 +223,6 @@ namespace Recyclable.Collections
|
|||||||
return values[middle];
|
return values[middle];
|
||||||
}
|
}
|
||||||
|
|
||||||
// [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
|
||||||
// public static T[] Resize(int newSize)
|
|
||||||
// // ArrayPool<T> arrayPool = _arrayPool;
|
|
||||||
// => newSize >= RecyclableDefaults.MinPooledArrayLength
|
|
||||||
// ? _arrayPool.Rent(newSize)
|
|
||||||
// : new T[newSize];
|
|
||||||
|
|
||||||
internal static readonly ArrayPool<T> _arrayPool = ArrayPool<T>.Create();
|
internal static readonly ArrayPool<T> _arrayPool = ArrayPool<T>.Create();
|
||||||
|
|
||||||
private static readonly bool NeedsClearing = !typeof(T).IsValueType;
|
private static readonly bool NeedsClearing = !typeof(T).IsValueType;
|
||||||
@@ -271,7 +230,6 @@ namespace Recyclable.Collections
|
|||||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public static void ResizeAndCopy(RecyclableList<T> sourceList, int newSize)
|
public static void ResizeAndCopy(RecyclableList<T> sourceList, int newSize)
|
||||||
{
|
{
|
||||||
// ArrayPool<T> arrayPool = _arrayPool;
|
|
||||||
T[] newMemoryBlock = newSize >= RecyclableDefaults.MinPooledArrayLength
|
T[] newMemoryBlock = newSize >= RecyclableDefaults.MinPooledArrayLength
|
||||||
? _arrayPool.Rent(newSize)
|
? _arrayPool.Rent(newSize)
|
||||||
: new T[newSize];
|
: new T[newSize];
|
||||||
@@ -280,7 +238,6 @@ namespace Recyclable.Collections
|
|||||||
T[] oldMemoryBlock = sourceList._memoryBlock;
|
T[] oldMemoryBlock = sourceList._memoryBlock;
|
||||||
|
|
||||||
// & WAS SLOWER AS ARRAY
|
// & WAS SLOWER AS ARRAY
|
||||||
// new Span<T>(oldMemoryBlock).CopyTo(newMemoryBlock);
|
|
||||||
Array.Copy(oldMemoryBlock, newMemoryBlock, oldMemoryBlock.Length);
|
Array.Copy(oldMemoryBlock, newMemoryBlock, oldMemoryBlock.Length);
|
||||||
|
|
||||||
if (oldMemoryBlock.Length >= RecyclableDefaults.MinPooledArrayLength)
|
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.
|
// If anything, it has been already cleared above, so we don't need to repeat it.
|
||||||
_arrayPool.Return(oldMemoryBlock, NeedsClearing);
|
_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<T> sourceList)
|
|
||||||
{
|
|
||||||
// ArrayPool<T> 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<T>._arrayPool.Rent(newSize)
|
|
||||||
// : new T[newSize];
|
|
||||||
|
|
||||||
// & WAS SLOWER WITHOUT
|
|
||||||
T[] oldMemoryBlock = sourceList._memoryBlock;
|
|
||||||
|
|
||||||
// & WAS SLOWER AS ARRAY
|
|
||||||
new Span<T>(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;
|
sourceList._memoryBlock = newMemoryBlock;
|
||||||
|
|||||||
Reference in new issue
Block a user