Cleanup. Hints and warnings either disabled or fixed. Typos fixed.
This commit is contained in:
1 parent
2317f53d51
commit
c20b252a6c
17 files changed
+108
-68
No files matched your search
@@ -13,10 +13,12 @@ namespace Recyclable.Collections
|
||||
_memory = memory;
|
||||
}
|
||||
|
||||
#pragma warning disable RCS1085
|
||||
private T[] _memory;
|
||||
public T[] Memory { get => _memory; set => _memory = value; }
|
||||
|
||||
private MemoryBucket<T>? _nextBucket;
|
||||
public MemoryBucket<T>? NextBucket { get => _nextBucket; set => _nextBucket = value; }
|
||||
#pragma warning restore RCS1085
|
||||
}
|
||||
}
|
||||
@@ -271,7 +271,9 @@ namespace Recyclable.Collections
|
||||
: RecyclableArrayPool<T>.Null;
|
||||
}
|
||||
|
||||
#pragma warning disable CA2208
|
||||
public static void ThrowIndexOutOfRangeException(in string message) => throw new ArgumentOutOfRangeException("index", message);
|
||||
#pragma warning restore CA2208
|
||||
public static void ThrowArgumentOutOfRangeException(in string argumentName, in string message) => throw new ArgumentOutOfRangeException(argumentName, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,12 @@ namespace Recyclable.Collections
|
||||
{
|
||||
private static readonly ArrayPool<T[]> _defaultMemoryBlocksPool = ArrayPool<T[]>.Create();
|
||||
private static readonly ArrayPool<T> _defaultBlockArrayPool = ArrayPool<T>.Create();
|
||||
#pragma warning disable CA1825
|
||||
private static readonly T[][] _emptyMemoryBlocksArray = new T[0][];
|
||||
private static readonly T[] _emptyBlockArray = new T[0];
|
||||
#pragma warning restore CA1825
|
||||
private static readonly bool _defaultIsNull = default(T) == null;
|
||||
private static readonly bool NeedsClearing = !typeof(T).IsValueType;
|
||||
|
||||
internal int _blockSize;
|
||||
internal byte _blockSizePow2BitShift;
|
||||
@@ -23,9 +26,7 @@ namespace Recyclable.Collections
|
||||
internal int _nextItemIndex;
|
||||
private int _reservedBlockCount;
|
||||
|
||||
private static readonly bool NeedsClearing = !typeof(T).IsValueType;
|
||||
|
||||
private ArrayPool<T[]> _memoryBlocksPool;
|
||||
private readonly ArrayPool<T[]> _memoryBlocksPool;
|
||||
private ArrayPool<T> _blockArrayPool;
|
||||
#nullable disable
|
||||
internal T[][] _memoryBlocks;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Recyclable.Collections
|
||||
{
|
||||
internal static class RecyclableQueueHelpers
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int ToArrayIndex(long index, int blockSize) => (int)(index / blockSize);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static long ToItemIndex(long index, int blockSize) => index % blockSize;
|
||||
}
|
||||
}
|
||||
@@ -95,18 +95,12 @@ namespace Recyclable.Collections
|
||||
set => SetItem(index, value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int ToArrayIndex(long index, int blockSize) => (int)(index / blockSize);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static long ToItemIndex(long index, int blockSize) => index % blockSize;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void SetItem(long index, T value)
|
||||
{
|
||||
long absoluteIndex = GetAbsoluteIndex(index, RemovedCount);
|
||||
int arrayIndex = ToArrayIndex(absoluteIndex, BlockSize);
|
||||
long itemIndex = ToItemIndex(absoluteIndex, BlockSize);
|
||||
int arrayIndex = RecyclableQueueHelpers.ToArrayIndex(absoluteIndex, BlockSize);
|
||||
long itemIndex = RecyclableQueueHelpers.ToItemIndex(absoluteIndex, BlockSize);
|
||||
Memory[arrayIndex][itemIndex] = value;
|
||||
}
|
||||
|
||||
@@ -114,8 +108,8 @@ namespace Recyclable.Collections
|
||||
private T GetItem(long index)
|
||||
{
|
||||
long absoluteIndex = GetAbsoluteIndex(index, RemovedCount);
|
||||
int arrayIndex = ToArrayIndex(absoluteIndex, BlockSize);
|
||||
long itemIndex = ToItemIndex(absoluteIndex, BlockSize);
|
||||
int arrayIndex = RecyclableQueueHelpers.ToArrayIndex(absoluteIndex, BlockSize);
|
||||
long itemIndex = RecyclableQueueHelpers.ToItemIndex(absoluteIndex, BlockSize);
|
||||
return Memory[arrayIndex][itemIndex];
|
||||
}
|
||||
|
||||
@@ -156,10 +150,10 @@ namespace Recyclable.Collections
|
||||
{
|
||||
RemoveBlock(Memory.Count - 1);
|
||||
}
|
||||
#pragma warning disable RCS1075 // We want to try returning as many arrays, as possible, before the list is cleared.
|
||||
catch (Exception)
|
||||
#pragma warning restore RCS1075
|
||||
{
|
||||
// We want to try returning as many arrays, as possible, before
|
||||
// the list is cleared.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,6 +165,7 @@ namespace Recyclable.Collections
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CS0618
|
||||
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);
|
||||
@@ -178,6 +173,8 @@ namespace Recyclable.Collections
|
||||
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));
|
||||
#pragma warning restore CS0618
|
||||
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user