Cleanup
This commit is contained in:
1 parent
9caa6b7eaa
commit
ea0598cc35
1 file changed
+11
-78
@@ -4,42 +4,22 @@ namespace Recyclable.Collections
|
||||
{
|
||||
public partial class RecyclableLongList<T>
|
||||
{
|
||||
// & WAS SLOWER
|
||||
// [StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
// [StructLayout(LayoutKind.Sequential)]
|
||||
public struct Enumerator : IEnumerator<T>
|
||||
{
|
||||
// & WAS SLOWER WITHOUT
|
||||
#nullable disable
|
||||
private static readonly T _default = default;
|
||||
#nullable restore
|
||||
#nullable disable
|
||||
private static readonly T _default = default;
|
||||
#nullable restore
|
||||
|
||||
private static readonly bool _isReferenceType = !typeof(T).IsValueType;
|
||||
|
||||
private int _currentBlockIndex;
|
||||
private int _currentItemIndex;
|
||||
private readonly RecyclableLongList<T> _list;
|
||||
// & WAS SLOWER WITHOUT
|
||||
#nullable disable
|
||||
private T _current;
|
||||
#nullable restore
|
||||
// & WAS SLOWER
|
||||
// private readonly ulong _enumeratorVersion;
|
||||
// public T Current => _enumeratorVersion != _list._version ? throw new InvalidOperationException() : _current;
|
||||
|
||||
#nullable disable
|
||||
private T _current;
|
||||
#nullable restore
|
||||
public readonly T Current => _current;
|
||||
// & WAS SLOWER
|
||||
// get => _currentItemIndex > 0
|
||||
// ? _list._memoryBlocks[_currentBlockIndex][_currentItemIndex - 1]
|
||||
// : _list._memoryBlocks[_currentBlockIndex - 1][_list._blockSize - 1];
|
||||
// & WAS SLOWER
|
||||
// get => _currentItemIndex != RecyclableDefaults.BlockIndexLimit
|
||||
// ? _currentItemIndex > 0
|
||||
// ? _list._memoryBlocks[_currentBlockIndex][_currentItemIndex - 1]
|
||||
// & WAS SLOWER
|
||||
// : _list._memoryBlocks[_currentBlockIndex - 1][_list._blockSize - 1]
|
||||
// ? _current
|
||||
// : throw new IndexOutOfRangeException();
|
||||
// & WAS SLOWER
|
||||
// {
|
||||
// get
|
||||
@@ -61,12 +41,6 @@ namespace Recyclable.Collections
|
||||
// : _list._memoryBlocks[_currentBlockIndex - 1][_list._blockSize - 1];
|
||||
// }
|
||||
// }
|
||||
|
||||
// & WAS SLOWER
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// [MethodImpl(MethodImplOptions.NoInlining)]
|
||||
// [MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
// [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public bool MoveNext()
|
||||
{
|
||||
// & WAS SLOWER
|
||||
@@ -76,17 +50,10 @@ namespace Recyclable.Collections
|
||||
// }
|
||||
//
|
||||
// Contract.EndContractBlock();
|
||||
|
||||
// & WAS SLOWER WITHOUT
|
||||
var list = _list;
|
||||
// & WAS SLOWER
|
||||
// ref var currentBlockIndex = ref _currentBlockIndex;
|
||||
// & WAS SLOWER
|
||||
// ref var currentItemIndex = ref _currentItemIndex;
|
||||
|
||||
if (_currentBlockIndex < list._lastBlockWithData)
|
||||
{
|
||||
// & WAS SLOWER WITHOUT
|
||||
_current = list._memoryBlocks[_currentBlockIndex][_currentItemIndex];
|
||||
if (_currentItemIndex + 1 < list._blockSize)
|
||||
{
|
||||
@@ -100,44 +67,19 @@ namespace Recyclable.Collections
|
||||
|
||||
return true;
|
||||
}
|
||||
// & WAS SLOWER
|
||||
// else if (list._longCount == 0)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// Move to the next item if we're within block boundaries, otherwise report end of collection.
|
||||
else if (list._longCount > 0 && _currentItemIndex < (list._nextItemIndex > 0 ? list._nextItemIndex : list._blockSize))
|
||||
{
|
||||
// & WAS SLOWER WITHOUT
|
||||
_current = list._memoryBlocks[_currentBlockIndex][_currentItemIndex];
|
||||
// & WAS SLOWER WITHOUT
|
||||
_currentItemIndex++;
|
||||
return true;
|
||||
}
|
||||
// & WAS SLOWER
|
||||
// else if (_currentItemIndex != RecyclableDefaults.BlockIndexLimit)
|
||||
// {
|
||||
// _currentItemIndex = RecyclableDefaults.BlockIndexLimit;
|
||||
// _current = _default;
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
readonly object IEnumerator.Current => _current;
|
||||
// & WAS SLOWER
|
||||
// get => _currentItemIndex > 0
|
||||
// ? _list._memoryBlocks[_currentBlockIndex][_currentItemIndex - 1]
|
||||
// : (object)_list._memoryBlocks[_currentBlockIndex - 1][_list._blockSize - 1];
|
||||
// & WAS SLOWER
|
||||
// get => _currentItemIndex != RecyclableDefaults.BlockIndexLimit
|
||||
// // ? _currentItemIndex > 0
|
||||
// // ? _list._memoryBlocks[_currentBlockIndex][_currentItemIndex - 1]
|
||||
// // : _list._memoryBlocks[_currentBlockIndex - 1][_list._blockSize - 1]
|
||||
// // & WAS SLOWER
|
||||
// ? _current
|
||||
// : throw new IndexOutOfRangeException();
|
||||
#nullable restore
|
||||
// & WAS SLOWER
|
||||
// readonly object? IEnumerator.Current => _enumeratorVersion != _list._version ? throw new InvalidOperationException() : _current;
|
||||
@@ -149,11 +91,6 @@ namespace Recyclable.Collections
|
||||
// // throw new InvalidOperationException();
|
||||
// // }
|
||||
|
||||
// // if (_list._longCount == 0 || _currentItemIndex == RecyclableDefaults.BlockIndexLimit)
|
||||
// // {
|
||||
// // throw new IndexOutOfRangeException();
|
||||
// // }
|
||||
|
||||
// // Contract.EndContractBlock();
|
||||
|
||||
// return _currentItemIndex > 0
|
||||
@@ -161,27 +98,23 @@ namespace Recyclable.Collections
|
||||
// : _list._memoryBlocks[_currentBlockIndex - 1][_list._blockSize - 1];
|
||||
// }
|
||||
// }
|
||||
|
||||
public Enumerator(RecyclableLongList<T> list)
|
||||
{
|
||||
// & WAS SLOWER WITHOUT
|
||||
_current = _default;
|
||||
_currentBlockIndex = 0;
|
||||
// & WAS SLOWER
|
||||
//_currentBlockIndex = -1;
|
||||
_currentItemIndex = 0;
|
||||
_list = list;
|
||||
// & WAS SLOWER
|
||||
// _enumeratorVersion = list._version;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
// & WAS SLOWER WITHOUT
|
||||
// if (_enumeratorVersion != _list._version)
|
||||
// {
|
||||
// throw new InvalidOperationException();
|
||||
// }
|
||||
|
||||
_current = _default;
|
||||
_currentBlockIndex = 0;
|
||||
// & WAS SLOWER
|
||||
//_currentBlockIndex = -1;
|
||||
_currentItemIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user