Skip to content

Commit b88304c

Browse files
ProjectStateChangeDetector: Use HashSet for unique items
Update ProjectStateChangeDetector to use a dedicated HashSet instance to compute the most recent unique items.
1 parent a84a61a commit b88304c

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Discovery/ProjectStateChangeDetector.Comparer.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Discovery/ProjectStateChangeDetector.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ namespace Microsoft.VisualStudio.Razor.Discovery;
2323
[Export(typeof(IRazorStartupService))]
2424
internal partial class ProjectStateChangeDetector : IRazorStartupService, IDisposable
2525
{
26-
private readonly record struct Work(ProjectKey Key, ProjectId? Id);
26+
private readonly record struct Work(ProjectKey Key, ProjectId? Id)
27+
{
28+
public bool Equals(Work other)
29+
=> Key.Equals(other.Key);
30+
31+
public override int GetHashCode()
32+
=> Key.GetHashCode();
33+
}
2734

2835
private static readonly TimeSpan s_delay = TimeSpan.FromSeconds(1);
2936

@@ -34,6 +41,7 @@ internal partial class ProjectStateChangeDetector : IRazorStartupService, IDispo
3441

3542
private readonly CancellationTokenSource _disposeTokenSource;
3643
private readonly AsyncBatchingWorkQueue<Work> _workQueue;
44+
private readonly HashSet<Work> _workerSet;
3745

3846
/// <summary>
3947
/// A map of assembly path strings to ProjectKeys. This will be cleared when the solution is closed.
@@ -63,6 +71,7 @@ public ProjectStateChangeDetector(
6371
_projectManager = projectManager;
6472
_options = options;
6573

74+
_workerSet = [];
6675
_disposeTokenSource = new();
6776
_workQueue = new AsyncBatchingWorkQueue<Work>(
6877
delay,
@@ -95,7 +104,9 @@ public void Dispose()
95104

96105
private ValueTask ProcessBatchAsync(ImmutableArray<Work> items, CancellationToken token)
97106
{
98-
foreach (var (projectKey, projectId) in items.GetMostRecentUniqueItems(Comparer.Instance))
107+
_workerSet.Clear();
108+
109+
foreach (var (projectKey, projectId) in items.GetMostRecentUniqueItems(_workerSet))
99110
{
100111
if (token.IsCancellationRequested)
101112
{

0 commit comments

Comments
 (0)