diff --git a/Recyclable.Collections/RecyclableLongList.Enumerator.cs b/Recyclable.Collections/RecyclableLongList.Enumerator.cs index 693b1b6..3a5177a 100644 --- a/Recyclable.Collections/RecyclableLongList.Enumerator.cs +++ b/Recyclable.Collections/RecyclableLongList.Enumerator.cs @@ -4,42 +4,22 @@ namespace Recyclable.Collections { public partial class RecyclableLongList { - // & WAS SLOWER - // [StructLayout(LayoutKind.Sequential, Pack = 1)] - // [StructLayout(LayoutKind.Sequential)] public struct Enumerator : IEnumerator { - // & 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 _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 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; }