diff --git a/Recyclable.Collections/RecyclableLongList.Enumerator.cs b/Recyclable.Collections/RecyclableLongList.Enumerator.cs index 6fb02cc..353f2d3 100644 --- a/Recyclable.Collections/RecyclableLongList.Enumerator.cs +++ b/Recyclable.Collections/RecyclableLongList.Enumerator.cs @@ -26,7 +26,7 @@ namespace Recyclable.Collections { var list = _list; - if (_currentBlockIndex <= list._lastBlockWithData && _currentItemIndex <= (_currentBlockIndex == list._lastBlockWithData && list._nextItemIndex > 0 ? list._nextItemIndex - 1: list._blockSizeMinus1)) + if (_currentBlockIndex < list._lastBlockWithData) { _current = list._memoryBlocks[_currentBlockIndex][_currentItemIndex]; if (_currentItemIndex + 1 < list._blockSize) @@ -41,7 +41,14 @@ namespace Recyclable.Collections return true; } + // Move to the next item if we're within block boundaries, otherwise report end of collection. + if (list._longCount > 0 && _currentItemIndex < (list._nextItemIndex > 0 ? list._nextItemIndex : list._blockSize)) + { + _current = list._memoryBlocks[_currentBlockIndex][_currentItemIndex]; + _currentItemIndex++; + return true; + } return false; }