From 5e8f01f6221227db70e090c291d23475c7a90a2b Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 9 Apr 2026 15:17:59 +1000 Subject: [PATCH] use HashSet for usedSnippets and usedIncludes --- .../Processing/IncludeProcessor.cs | 6 +++--- .../Processing/MarkdownProcessor.cs | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/MarkdownSnippets/Processing/IncludeProcessor.cs b/src/MarkdownSnippets/Processing/IncludeProcessor.cs index 6b77ecf2..59a2bda0 100644 --- a/src/MarkdownSnippets/Processing/IncludeProcessor.cs +++ b/src/MarkdownSnippets/Processing/IncludeProcessor.cs @@ -21,7 +21,7 @@ public IncludeProcessor( this.allFiles = allFiles; } - public bool TryProcessInclude(List lines, Line line, List used, int index, List missing, string? relativePath) + public bool TryProcessInclude(List lines, Line line, ICollection used, int index, List missing, string? relativePath) { var current = line.Current; @@ -79,7 +79,7 @@ static string GetIncludeKey(CharSpan substring) return false; } - void Inner(List lines, Line line, List used, int index, List missing, string includeKey, string? relativePath) + void Inner(List lines, Line line, ICollection used, int index, List missing, string includeKey, string? relativePath) { if (includesLookup.TryGetValue(includeKey, out var include)) { @@ -125,7 +125,7 @@ void Inner(List lines, Line line, List used, int index, List"; } - void AddInclude(List lines, Line line, List used, int index, Include include, bool writePath) + void AddInclude(List lines, Line line, ICollection used, int index, Include include, bool writePath) { used.Add(include); var linesToInject = BuildIncludes(line, include, writePath).ToList(); diff --git a/src/MarkdownSnippets/Processing/MarkdownProcessor.cs b/src/MarkdownSnippets/Processing/MarkdownProcessor.cs index 939680de..3a4bc147 100644 --- a/src/MarkdownSnippets/Processing/MarkdownProcessor.cs +++ b/src/MarkdownSnippets/Processing/MarkdownProcessor.cs @@ -129,8 +129,8 @@ internal ProcessResult Apply(List lines, string newLine, string? relativeP var missingSnippets = new List(); var validationErrors = new List(); var missingIncludes = new List(); - var usedSnippets = new List(); - var usedIncludes = new List(); + var usedSnippets = new HashSet(); + var usedIncludes = new HashSet(); var builder = new StringBuilder(); Line? tocLine = null; @@ -263,8 +263,8 @@ void AppendWebSnippet(string url, string snippetKey, string? viewUrl = null) return new( missingSnippets: missingSnippets, - usedSnippets: usedSnippets.Distinct().ToList(), - usedIncludes: usedIncludes.Distinct().ToList(), + usedSnippets: usedSnippets.ToList(), + usedIncludes: usedIncludes.ToList(), missingIncludes: missingIncludes, validationErrors: validationErrors); } @@ -292,7 +292,7 @@ bool ValidateContent(string? relativePath, Line line, List vali return found; } - void ProcessSnippetLine(Action appendLine, List missings, List used, string key, string? relativePath, Line line) + void ProcessSnippetLine(Action appendLine, List missings, HashSet used, string key, string? relativePath, Line line) { appendLine($""); @@ -300,7 +300,7 @@ void ProcessSnippetLine(Action appendLine, List missings { appendSnippets(key, snippetsForKey, appendLine); appendLine(""); - used.AddRange(snippetsForKey); + used.UnionWith(snippetsForKey); return; } @@ -312,7 +312,7 @@ void ProcessSnippetLine(Action appendLine, List missings appendLine(""); } - void ProcessWebSnippetLine(Action appendLine, List missings, List used, string url, string snippetKey, string? viewUrl, Line line) + void ProcessWebSnippetLine(Action appendLine, List missings, HashSet used, string url, string snippetKey, string? viewUrl, Line line) { var commentText = viewUrl == null ? $""