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>
|
public partial class RecyclableLongList<T>
|
||||||
{
|
{
|
||||||
// & WAS SLOWER
|
|
||||||
// [StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
||||||
// [StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Enumerator : IEnumerator<T>
|
public struct Enumerator : IEnumerator<T>
|
||||||
{
|
{
|
||||||
// & WAS SLOWER WITHOUT
|
#nullable disable
|
||||||
#nullable disable
|
private static readonly T _default = default;
|
||||||
private static readonly T _default = default;
|
#nullable restore
|
||||||
#nullable restore
|
|
||||||
|
|
||||||
private static readonly bool _isReferenceType = !typeof(T).IsValueType;
|
private static readonly bool _isReferenceType = !typeof(T).IsValueType;
|
||||||
|
|
||||||
private int _currentBlockIndex;
|
private int _currentBlockIndex;
|
||||||
private int _currentItemIndex;
|
private int _currentItemIndex;
|
||||||
private readonly RecyclableLongList<T> _list;
|
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;
|
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
|
// & WAS SLOWER
|
||||||
// {
|
// {
|
||||||
// get
|
// get
|
||||||
@@ -61,12 +41,6 @@ namespace Recyclable.Collections
|
|||||||
// : _list._memoryBlocks[_currentBlockIndex - 1][_list._blockSize - 1];
|
// : _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()
|
public bool MoveNext()
|
||||||
{
|
{
|
||||||
// & WAS SLOWER
|
// & WAS SLOWER
|
||||||
@@ -76,17 +50,10 @@ namespace Recyclable.Collections
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Contract.EndContractBlock();
|
// Contract.EndContractBlock();
|
||||||
|
|
||||||
// & WAS SLOWER WITHOUT
|
|
||||||
var list = _list;
|
var list = _list;
|
||||||
// & WAS SLOWER
|
|
||||||
// ref var currentBlockIndex = ref _currentBlockIndex;
|
|
||||||
// & WAS SLOWER
|
|
||||||
// ref var currentItemIndex = ref _currentItemIndex;
|
|
||||||
|
|
||||||
if (_currentBlockIndex < list._lastBlockWithData)
|
if (_currentBlockIndex < list._lastBlockWithData)
|
||||||
{
|
{
|
||||||
// & WAS SLOWER WITHOUT
|
|
||||||
_current = list._memoryBlocks[_currentBlockIndex][_currentItemIndex];
|
_current = list._memoryBlocks[_currentBlockIndex][_currentItemIndex];
|
||||||
if (_currentItemIndex + 1 < list._blockSize)
|
if (_currentItemIndex + 1 < list._blockSize)
|
||||||
{
|
{
|
||||||
@@ -100,44 +67,19 @@ namespace Recyclable.Collections
|
|||||||
|
|
||||||
return true;
|
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.
|
// 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))
|
else if (list._longCount > 0 && _currentItemIndex < (list._nextItemIndex > 0 ? list._nextItemIndex : list._blockSize))
|
||||||
{
|
{
|
||||||
// & WAS SLOWER WITHOUT
|
|
||||||
_current = list._memoryBlocks[_currentBlockIndex][_currentItemIndex];
|
_current = list._memoryBlocks[_currentBlockIndex][_currentItemIndex];
|
||||||
// & WAS SLOWER WITHOUT
|
|
||||||
_currentItemIndex++;
|
_currentItemIndex++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// & WAS SLOWER
|
|
||||||
// else if (_currentItemIndex != RecyclableDefaults.BlockIndexLimit)
|
|
||||||
// {
|
|
||||||
// _currentItemIndex = RecyclableDefaults.BlockIndexLimit;
|
|
||||||
// _current = _default;
|
|
||||||
// }
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
readonly object IEnumerator.Current => _current;
|
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
|
#nullable restore
|
||||||
// & WAS SLOWER
|
// & WAS SLOWER
|
||||||
// readonly object? IEnumerator.Current => _enumeratorVersion != _list._version ? throw new InvalidOperationException() : _current;
|
// readonly object? IEnumerator.Current => _enumeratorVersion != _list._version ? throw new InvalidOperationException() : _current;
|
||||||
@@ -149,11 +91,6 @@ namespace Recyclable.Collections
|
|||||||
// // throw new InvalidOperationException();
|
// // throw new InvalidOperationException();
|
||||||
// // }
|
// // }
|
||||||
|
|
||||||
// // if (_list._longCount == 0 || _currentItemIndex == RecyclableDefaults.BlockIndexLimit)
|
|
||||||
// // {
|
|
||||||
// // throw new IndexOutOfRangeException();
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // Contract.EndContractBlock();
|
// // Contract.EndContractBlock();
|
||||||
|
|
||||||
// return _currentItemIndex > 0
|
// return _currentItemIndex > 0
|
||||||
@@ -161,27 +98,23 @@ namespace Recyclable.Collections
|
|||||||
// : _list._memoryBlocks[_currentBlockIndex - 1][_list._blockSize - 1];
|
// : _list._memoryBlocks[_currentBlockIndex - 1][_list._blockSize - 1];
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public Enumerator(RecyclableLongList<T> list)
|
public Enumerator(RecyclableLongList<T> list)
|
||||||
{
|
{
|
||||||
// & WAS SLOWER WITHOUT
|
|
||||||
_current = _default;
|
_current = _default;
|
||||||
_currentBlockIndex = 0;
|
_currentBlockIndex = 0;
|
||||||
// & WAS SLOWER
|
|
||||||
//_currentBlockIndex = -1;
|
|
||||||
_currentItemIndex = 0;
|
_currentItemIndex = 0;
|
||||||
_list = list;
|
_list = list;
|
||||||
// & WAS SLOWER
|
|
||||||
// _enumeratorVersion = list._version;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
// & WAS SLOWER WITHOUT
|
// if (_enumeratorVersion != _list._version)
|
||||||
|
// {
|
||||||
|
// throw new InvalidOperationException();
|
||||||
|
// }
|
||||||
|
|
||||||
_current = _default;
|
_current = _default;
|
||||||
_currentBlockIndex = 0;
|
_currentBlockIndex = 0;
|
||||||
// & WAS SLOWER
|
|
||||||
//_currentBlockIndex = -1;
|
|
||||||
_currentItemIndex = 0;
|
_currentItemIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user