From 5a2ae1c261c65b2d2b9d05362aaad38ae6819ab2 Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sat, 5 Aug 2023 19:18:13 +0200 Subject: [PATCH] RecyclableLongList.Remove & .RemoveAt fixed to correctly set _lastBlockWithData to -1, when we remove the last item. --- Recyclable.Collections/RecyclableLongList.cs | 30 ++++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Recyclable.Collections/RecyclableLongList.cs b/Recyclable.Collections/RecyclableLongList.cs index 5aa8da0..b316a72 100644 --- a/Recyclable.Collections/RecyclableLongList.cs +++ b/Recyclable.Collections/RecyclableLongList.cs @@ -921,10 +921,7 @@ namespace Recyclable.Collections if (_nextItemIndex > 0) { - if (--_nextItemIndex == 0) - { - _lastBlockWithData--; - } + _nextItemIndex--; } else { @@ -932,6 +929,11 @@ namespace Recyclable.Collections _nextItemBlockIndex--; } + if (_nextItemIndex == 0) + { + _lastBlockWithData--; + } + if (NeedsClearing) { #nullable disable @@ -987,10 +989,7 @@ namespace Recyclable.Collections if (_nextItemIndex > 0) { - if (--_nextItemIndex == 0) - { - _lastBlockWithData--; - } + _nextItemIndex--; } else { @@ -998,6 +997,11 @@ namespace Recyclable.Collections _nextItemBlockIndex--; } + if (_nextItemIndex == 0) + { + _lastBlockWithData--; + } + if (NeedsClearing) { #nullable disable @@ -1023,10 +1027,7 @@ namespace Recyclable.Collections if (_nextItemIndex > 0) { - if (--_nextItemIndex == 0) - { - _lastBlockWithData--; - } + _nextItemIndex--; } else { @@ -1034,6 +1035,11 @@ namespace Recyclable.Collections _nextItemBlockIndex--; } + if (_nextItemIndex == 0) + { + _lastBlockWithData--; + } + if (NeedsClearing) { #nullable disable