From 6bea2072aeaded9c8e7b33663f6f83eb55be2657 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 20 Jun 2026 13:30:52 +0200 Subject: [PATCH] Use a HashSet for the nodes awaiting a start location InsertMissingTokensDecorator removes a pending node by value and uses whether it was still present, so a HashSet keys that membership-removal on O(1); iteration order is irrelevant because every pending node receives the same location. Rename the field to nodesAwaitingStartLocation for clarity. Assisted-by: Claude:claude-opus-4-8:Claude Code --- .../OutputVisitor/InsertMissingTokensDecorator.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs index 470cde19b..3aab6fcea 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor // Nodes that have been started but whose first token has not been written yet. The start // location of a node is the position of its first printed token (not the StartNode position, // which precedes any leading newline/indentation), so it is assigned lazily on the next write. - readonly List nodesAwaitingStart = new List(); + readonly HashSet nodesAwaitingStartLocation = new HashSet(); // Position immediately after the most recently written token. A node's end location is the end // of its last token (not the EndNode position, which follows the trailing newline/indentation). @@ -49,12 +49,12 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor void AssignPendingStartLocations() { - if (nodesAwaitingStart.Count == 0) + if (nodesAwaitingStartLocation.Count == 0) return; TextLocation location = locationProvider.Location; - foreach (var node in nodesAwaitingStart) + foreach (var node in nodesAwaitingStartLocation) node.StorePrintStart(location); - nodesAwaitingStart.Clear(); + nodesAwaitingStartLocation.Clear(); } public override void StartNode(AstNode node) @@ -66,7 +66,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor currentList.Add(node); nodes.Push(currentList); currentList = new List(); - nodesAwaitingStart.Add(node); + nodesAwaitingStartLocation.Add(node); } else if (node is Comment comment) { @@ -86,7 +86,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor if (node is not Trivia) { // A node that printed no tokens of its own collapses to a zero-width span here. - if (nodesAwaitingStart.Remove(node)) + if (nodesAwaitingStartLocation.Remove(node)) node.StorePrintStart(lastTokenEnd); node.StorePrintEnd(lastTokenEnd); System.Diagnostics.Debug.Assert(currentList != null);