RecyclableList<T>.Helpers renamed to RecyclableListHelpers and made top-level class for better performance.
This commit is contained in:
1 parent
db8b0602c0
commit
11fd6e3dd0
6 files changed
+26
-29
No files matched your search
@@ -3,9 +3,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Recyclable.Collections
|
||||
{
|
||||
public partial class RecyclableList<T>
|
||||
{
|
||||
internal static class Helpers
|
||||
internal static class RecyclableListHelpers<T>
|
||||
{
|
||||
[Obsolete("This method MAY be removed in the near future.")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -77,6 +75,7 @@ namespace Recyclable.Collections
|
||||
return newCapacity;
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("This method WILL be removed in the near future. Please use the existing enumerators instead of it.")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static IEnumerable<T> Enumerate(RecyclableList<T[]> arrays, int chunkSize, long totalCount)
|
||||
@@ -269,5 +268,4 @@ namespace Recyclable.Collections
|
||||
private static void Swap(IList<T> values, int xIndex, int yIndex)
|
||||
=> (values[yIndex], values[xIndex]) = (values[xIndex], values[yIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ namespace Recyclable.Collections
|
||||
{
|
||||
if (targetItemIdx + growByCount > capacity)
|
||||
{
|
||||
capacity = Helpers.EnsureCapacity(this, capacity + growByCount);
|
||||
capacity = RecyclableListHelpers<T>.EnsureCapacity(this, capacity + growByCount);
|
||||
memorySpan = new(_memoryBlock);
|
||||
available = capacity - targetItemIdx;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ namespace Recyclable.Collections
|
||||
|
||||
private void AddRangeWithKnownCount(IEnumerable<T> source, int targetItemIdx, int requiredAdditionalCapacity)
|
||||
{
|
||||
_ = Helpers.EnsureCapacity(this, targetItemIdx + requiredAdditionalCapacity);
|
||||
_ = RecyclableListHelpers<T>.EnsureCapacity(this, targetItemIdx + requiredAdditionalCapacity);
|
||||
|
||||
Span<T> memorySpan = new(_memoryBlock);
|
||||
foreach (var item in source)
|
||||
@@ -82,7 +82,7 @@ namespace Recyclable.Collections
|
||||
{
|
||||
if (initialCapacity > 0)
|
||||
{
|
||||
_memoryBlock = Helpers.Resize(_memoryBlock, initialCapacity);
|
||||
_memoryBlock = RecyclableListHelpers<T>.Resize(_memoryBlock, initialCapacity);
|
||||
_capacity = _memoryBlock.Length;
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ namespace Recyclable.Collections
|
||||
|
||||
public RecyclableList(IEnumerable<T> source, int initialCapacity = RecyclableDefaults.Capacity)
|
||||
{
|
||||
_memoryBlock = Helpers.Resize(_memoryBlock, initialCapacity);
|
||||
_memoryBlock = RecyclableListHelpers<T>.Resize(_memoryBlock, initialCapacity);
|
||||
_capacity = _memoryBlock.Length;
|
||||
AddRange(source);
|
||||
}
|
||||
@@ -149,7 +149,7 @@ namespace Recyclable.Collections
|
||||
}
|
||||
}
|
||||
|
||||
private int _capacity;
|
||||
internal int _capacity;
|
||||
public int Capacity
|
||||
{
|
||||
get => _capacity;
|
||||
@@ -157,7 +157,7 @@ namespace Recyclable.Collections
|
||||
{
|
||||
if (_capacity != value)
|
||||
{
|
||||
_memoryBlock = Helpers.Resize(_memoryBlock, value);
|
||||
_memoryBlock = RecyclableListHelpers<T>.Resize(_memoryBlock, value);
|
||||
_capacity = _memoryBlock.Length;
|
||||
_version++;
|
||||
}
|
||||
@@ -175,7 +175,7 @@ namespace Recyclable.Collections
|
||||
int requiredCapacity = _count + 1;
|
||||
if (_capacity < requiredCapacity)
|
||||
{
|
||||
_ = Helpers.EnsureCapacity(this, requiredCapacity);
|
||||
_ = RecyclableListHelpers<T>.EnsureCapacity(this, requiredCapacity);
|
||||
}
|
||||
|
||||
_memoryBlock[_count++] = item;
|
||||
@@ -194,14 +194,13 @@ namespace Recyclable.Collections
|
||||
int targetCapacity = _count + sourceItemsCount;
|
||||
if (_capacity < targetCapacity)
|
||||
{
|
||||
_ = Helpers.EnsureCapacity(this, targetCapacity);
|
||||
_ = RecyclableListHelpers<T>.EnsureCapacity(this, targetCapacity);
|
||||
}
|
||||
|
||||
var targetSpan = new Span<T>(_memoryBlock, _count, sourceItemsCount);
|
||||
Span<T> itemsSpan = new(items);
|
||||
itemsSpan.CopyTo(targetSpan);
|
||||
_count = targetCapacity;
|
||||
|
||||
_version++;
|
||||
}
|
||||
|
||||
@@ -217,7 +216,7 @@ namespace Recyclable.Collections
|
||||
int targetCapacity = _count + sourceItemsCount;
|
||||
if (_capacity < targetCapacity)
|
||||
{
|
||||
_ = Helpers.EnsureCapacity(this, targetCapacity);
|
||||
_ = RecyclableListHelpers<T>.EnsureCapacity(this, targetCapacity);
|
||||
}
|
||||
|
||||
var targetSpan = new Span<T>(_memoryBlock, _count, sourceItemsCount);
|
||||
@@ -239,7 +238,7 @@ namespace Recyclable.Collections
|
||||
var targetCapacity = _count + sourceItemsCount;
|
||||
if (_capacity < targetCapacity)
|
||||
{
|
||||
_ = Helpers.EnsureCapacity(this, targetCapacity);
|
||||
_ = RecyclableListHelpers<T>.EnsureCapacity(this, targetCapacity);
|
||||
}
|
||||
|
||||
items.CopyTo(_memoryBlock, _count);
|
||||
@@ -260,7 +259,7 @@ namespace Recyclable.Collections
|
||||
var targetCapacity = _count + sourceItemsCount;
|
||||
if (_capacity < targetCapacity)
|
||||
{
|
||||
_ = Helpers.EnsureCapacity(this, targetCapacity);
|
||||
_ = RecyclableListHelpers<T>.EnsureCapacity(this, targetCapacity);
|
||||
}
|
||||
|
||||
items.CopyTo(_memoryBlock, _count);
|
||||
@@ -281,7 +280,7 @@ namespace Recyclable.Collections
|
||||
var targetCapacity = _count + sourceItemsCount;
|
||||
if (_capacity < targetCapacity)
|
||||
{
|
||||
_ = Helpers.EnsureCapacity(this, targetCapacity);
|
||||
_ = RecyclableListHelpers<T>.EnsureCapacity(this, targetCapacity);
|
||||
}
|
||||
|
||||
var targetSpan = new Span<T>(_memoryBlock, _count, sourceItemsCount);
|
||||
@@ -314,7 +313,7 @@ namespace Recyclable.Collections
|
||||
int targetCapacity = _count + (int)sourceItemsCount;
|
||||
if (_capacity < targetCapacity)
|
||||
{
|
||||
_ = Helpers.EnsureCapacity(this, targetCapacity);
|
||||
_ = RecyclableListHelpers<T>.EnsureCapacity(this, targetCapacity);
|
||||
}
|
||||
|
||||
Span<T> targetSpan = new Span<T>(_memoryBlock)[_count..],
|
||||
@@ -415,7 +414,7 @@ namespace Recyclable.Collections
|
||||
int requestedCapacity = oldCount + 1;
|
||||
if (_capacity < requestedCapacity)
|
||||
{
|
||||
_ = Helpers.EnsureCapacity(this, requestedCapacity);
|
||||
_ = RecyclableListHelpers<T>.EnsureCapacity(this, requestedCapacity);
|
||||
}
|
||||
|
||||
if (oldCount > 0)
|
||||
|
||||
@@ -171,13 +171,13 @@ namespace Recyclable.Collections
|
||||
}
|
||||
}
|
||||
|
||||
public bool Contains(T item) => RecyclableList<T>.Helpers.Contains(Memory, item);
|
||||
public void CopyTo(T[] array, int arrayIndex) => RecyclableList<T>.Helpers.CopyTo(Memory, RemovedCount, BlockSize, (int)(LongCount % BlockSize), array, arrayIndex);
|
||||
public IEnumerable<T> Enumerate() => RecyclableList<T>.Helpers.Enumerate(Memory, BlockSize, LongCount);
|
||||
public IEnumerator<T> GetEnumerator() => RecyclableList<T>.Helpers.Enumerate(Memory, BlockSize, LongCount).GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => RecyclableList<T>.Helpers.Enumerate(Memory, BlockSize, LongCount).GetEnumerator();
|
||||
public int IndexOf(T item) => (int)GetRelativeIndex(RecyclableList<T>.Helpers.LongIndexOf(Memory, BlockSize, item, _equalityComparer));
|
||||
public long LongIndexOf(T item) => GetRelativeIndex(RecyclableList<T>.Helpers.LongIndexOf(Memory, BlockSize, item, _equalityComparer));
|
||||
public bool Contains(T item) => RecyclableListHelpers<T>.Contains(Memory, item);
|
||||
public void CopyTo(T[] array, int arrayIndex) => RecyclableListHelpers<T>.CopyTo(Memory, RemovedCount, BlockSize, (int)(LongCount % BlockSize), array, arrayIndex);
|
||||
public IEnumerable<T> Enumerate() => RecyclableListHelpers<T>.Enumerate(Memory, BlockSize, LongCount);
|
||||
public IEnumerator<T> GetEnumerator() => RecyclableListHelpers<T>.Enumerate(Memory, BlockSize, LongCount).GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => RecyclableListHelpers<T>.Enumerate(Memory, BlockSize, LongCount).GetEnumerator();
|
||||
public int IndexOf(T item) => (int)GetRelativeIndex(RecyclableListHelpers<T>.LongIndexOf(Memory, BlockSize, item, _equalityComparer));
|
||||
public long LongIndexOf(T item) => GetRelativeIndex(RecyclableListHelpers<T>.LongIndexOf(Memory, BlockSize, item, _equalityComparer));
|
||||
public void Insert(int index, T item) => throw new NotSupportedException();
|
||||
public void RemoveAt(int index) => throw new NotSupportedException();
|
||||
public bool TryDequeue(out T? item) => TryDequeue(this, out item);
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
BeginUpdate();
|
||||
try
|
||||
{
|
||||
RecyclableList<(TKey Key, TValue Value)>.Helpers.QuickSort(this, _comparer, _randomNumberGenerator);
|
||||
RecyclableListHelpers<(TKey, TValue)>.QuickSort(this, _comparer, _randomNumberGenerator);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -422,7 +422,7 @@ namespace Recyclable.CollectionsTests
|
||||
|
||||
// Act
|
||||
using RecyclableList<long> list = new(testData);
|
||||
RecyclableList<long>.Helpers.QuickSort(list);
|
||||
RecyclableListHelpers<long>.QuickSort(list);
|
||||
|
||||
// Validate
|
||||
_ = list.Count.Should().Be((int)itemsCount);
|
||||
|
||||
@@ -479,7 +479,7 @@ namespace Recyclable.CollectionsTests
|
||||
|
||||
// Act
|
||||
using RecyclableLongList<long> list = new(testData, minBlockSize: targetBlockSize);
|
||||
RecyclableList<long>.Helpers.QuickSort(list);
|
||||
RecyclableListHelpers<long>.QuickSort(list);
|
||||
|
||||
// Validate
|
||||
_ = list.LongCount.Should().Be(itemsCount);
|
||||
|
||||
Reference in new issue
Block a user