From 04f15094acd9e33a14ebb86a6f14f2ab0cbab20e Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Wed, 29 Oct 2025 22:04:44 +1000 Subject: [PATCH] nav history max size --- .../IdeNavigationHistoryService.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/SharpIDE.Application/Features/NavigationHistory/IdeNavigationHistoryService.cs b/src/SharpIDE.Application/Features/NavigationHistory/IdeNavigationHistoryService.cs index eac8eb3..8d201c3 100644 --- a/src/SharpIDE.Application/Features/NavigationHistory/IdeNavigationHistoryService.cs +++ b/src/SharpIDE.Application/Features/NavigationHistory/IdeNavigationHistoryService.cs @@ -5,7 +5,10 @@ namespace SharpIDE.Application.Features.NavigationHistory; public class IdeNavigationHistoryService { - private readonly Stack _backStack = new(); + private const int MaxHistorySize = 100; + + // Using LinkedList for back stack to efficiently remove oldest entries + private readonly LinkedList _backStack = new(); private IdeNavigationLocation? _current; private readonly Stack _forwardStack = new(); @@ -27,7 +30,8 @@ public class IdeNavigationHistoryService } if (_current is not null) { - _backStack.Push(_current); + _backStack.AddLast(_current); + if (_backStack.Count > MaxHistorySize) _backStack.RemoveFirst(); } _current = location; _forwardStack.Clear(); @@ -40,7 +44,8 @@ public class IdeNavigationHistoryService { _forwardStack.Push(_current); } - _current = _backStack.Pop(); + _current = _backStack.Last(); + _backStack.RemoveLast(); } public void GoForward() @@ -48,7 +53,7 @@ public class IdeNavigationHistoryService if (!CanGoForward) throw new InvalidOperationException("Cannot go forward, no history available."); if (_current is not null) { - _backStack.Push(_current); + _backStack.AddLast(_current); } _current = _forwardStack.Pop();