Skip to content

Commit bc566ab

Browse files
authored
use HashSet for usedSnippets and usedIncludes (#747)
1 parent d6d77b7 commit bc566ab

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/MarkdownSnippets/Processing/IncludeProcessor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public IncludeProcessor(
2121
this.allFiles = allFiles;
2222
}
2323

24-
public bool TryProcessInclude(List<Line> lines, Line line, List<Include> used, int index, List<MissingInclude> missing, string? relativePath)
24+
public bool TryProcessInclude(List<Line> lines, Line line, ICollection<Include> used, int index, List<MissingInclude> missing, string? relativePath)
2525
{
2626
var current = line.Current;
2727

@@ -79,7 +79,7 @@ static string GetIncludeKey(CharSpan substring)
7979
return false;
8080
}
8181

82-
void Inner(List<Line> lines, Line line, List<Include> used, int index, List<MissingInclude> missing, string includeKey, string? relativePath)
82+
void Inner(List<Line> lines, Line line, ICollection<Include> used, int index, List<MissingInclude> missing, string includeKey, string? relativePath)
8383
{
8484
if (includesLookup.TryGetValue(includeKey, out var include))
8585
{
@@ -125,7 +125,7 @@ void Inner(List<Line> lines, Line line, List<Include> used, int index, List<Miss
125125
line.Current = $"** Could not find include '{includeKey}' ** <!-- singleLineInclude: {includeKey} -->";
126126
}
127127

128-
void AddInclude(List<Line> lines, Line line, List<Include> used, int index, Include include, bool writePath)
128+
void AddInclude(List<Line> lines, Line line, ICollection<Include> used, int index, Include include, bool writePath)
129129
{
130130
used.Add(include);
131131
var linesToInject = BuildIncludes(line, include, writePath).ToList();

src/MarkdownSnippets/Processing/MarkdownProcessor.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ internal ProcessResult Apply(List<Line> lines, string newLine, string? relativeP
129129
var missingSnippets = new List<MissingSnippet>();
130130
var validationErrors = new List<ValidationError>();
131131
var missingIncludes = new List<MissingInclude>();
132-
var usedSnippets = new List<Snippet>();
133-
var usedIncludes = new List<Include>();
132+
var usedSnippets = new HashSet<Snippet>();
133+
var usedIncludes = new HashSet<Include>();
134134
var builder = new StringBuilder();
135135
Line? tocLine = null;
136136

@@ -263,8 +263,8 @@ void AppendWebSnippet(string url, string snippetKey, string? viewUrl = null)
263263

264264
return new(
265265
missingSnippets: missingSnippets,
266-
usedSnippets: usedSnippets.Distinct().ToList(),
267-
usedIncludes: usedIncludes.Distinct().ToList(),
266+
usedSnippets: usedSnippets.ToList(),
267+
usedIncludes: usedIncludes.ToList(),
268268
missingIncludes: missingIncludes,
269269
validationErrors: validationErrors);
270270
}
@@ -292,15 +292,15 @@ bool ValidateContent(string? relativePath, Line line, List<ValidationError> vali
292292
return found;
293293
}
294294

295-
void ProcessSnippetLine(Action<string> appendLine, List<MissingSnippet> missings, List<Snippet> used, string key, string? relativePath, Line line)
295+
void ProcessSnippetLine(Action<string> appendLine, List<MissingSnippet> missings, HashSet<Snippet> used, string key, string? relativePath, Line line)
296296
{
297297
appendLine($"<!-- snippet: {key} -->");
298298

299299
if (TryGetSnippets(key, relativePath, line.Path, out var snippetsForKey))
300300
{
301301
appendSnippets(key, snippetsForKey, appendLine);
302302
appendLine("<!-- endSnippet -->");
303-
used.AddRange(snippetsForKey);
303+
used.UnionWith(snippetsForKey);
304304
return;
305305
}
306306

@@ -312,7 +312,7 @@ void ProcessSnippetLine(Action<string> appendLine, List<MissingSnippet> missings
312312
appendLine("<!-- endSnippet -->");
313313
}
314314

315-
void ProcessWebSnippetLine(Action<string> appendLine, List<MissingSnippet> missings, List<Snippet> used, string url, string snippetKey, string? viewUrl, Line line)
315+
void ProcessWebSnippetLine(Action<string> appendLine, List<MissingSnippet> missings, HashSet<Snippet> used, string url, string snippetKey, string? viewUrl, Line line)
316316
{
317317
var commentText = viewUrl == null
318318
? $"<!-- web-snippet: {url}#{snippetKey} -->"

0 commit comments

Comments
 (0)