diff --git a/src/VisualStudio/Core/Def/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs b/src/VisualStudio/Core/Def/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs index 70688619dc1ff..a5baf1c34a3cb 100644 --- a/src/VisualStudio/Core/Def/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/FindReferences/Contexts/AbstractTableDataSourceFindUsagesContext.cs @@ -109,8 +109,8 @@ private abstract class AbstractTableDataSourceFindUsagesContext : /// private bool _currentlyGroupingByDefinition; - protected ImmutableList EntriesWhenNotGroupingByDefinition = ImmutableList.Empty; - protected ImmutableList EntriesWhenGroupingByDefinition = ImmutableList.Empty; + protected readonly List EntriesWhenNotGroupingByDefinition = []; + protected readonly List EntriesWhenGroupingByDefinition = []; private TableEntriesSnapshot? _lastSnapshot; public int CurrentVersionNumber { get; protected set; } @@ -182,6 +182,13 @@ protected AbstractTableDataSourceFindUsagesContext( protected abstract ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem definition, CancellationToken cancellationToken); protected abstract ValueTask OnReferenceFoundWorkerAsync(SourceReferenceItem reference, CancellationToken cancellationToken); + protected static void AddRange(List list, ArrayBuilder builder) + { + list.Capacity = list.Count + builder.Count; + foreach (var item in builder) + list.Add(item); + } + private static ImmutableArray SelectCustomColumnsToInclude(ImmutableArray customColumns, bool includeContainingTypeAndMemberColumns, bool includeKindColumn) { var customColumnsToInclude = ArrayBuilder.GetInstance(); @@ -570,10 +577,10 @@ public ITableEntriesSnapshot GetCurrentSnapshot() // Otherwise return the appropriate list based on how we're currently // grouping. var entries = _cleared - ? ImmutableList.Empty + ? [] : _currentlyGroupingByDefinition - ? EntriesWhenGroupingByDefinition - : EntriesWhenNotGroupingByDefinition; + ? EntriesWhenGroupingByDefinition.ToImmutableArray() + : EntriesWhenNotGroupingByDefinition.ToImmutableArray(); _lastSnapshot = new TableEntriesSnapshot(entries, CurrentVersionNumber); } diff --git a/src/VisualStudio/Core/Def/FindReferences/Contexts/WithReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/FindReferences/Contexts/WithReferencesFindUsagesContext.cs index 639bbc5bf1ffd..7d451d702441e 100644 --- a/src/VisualStudio/Core/Def/FindReferences/Contexts/WithReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/FindReferences/Contexts/WithReferencesFindUsagesContext.cs @@ -82,7 +82,7 @@ private async Task AddDeclarationEntriesAsync(DefinitionItem definition, bool ex { // We only include declaration entries in the entries we show when // not grouping by definition. - EntriesWhenNotGroupingByDefinition = EntriesWhenNotGroupingByDefinition.AddRange(entries); + AddRange(EntriesWhenNotGroupingByDefinition, entries); CurrentVersionNumber++; changed = true; } @@ -99,8 +99,13 @@ private bool HasDeclarationEntries(DefinitionItem definition) { lock (Gate) { - return EntriesWhenNotGroupingByDefinition.Any( - e => e.DefinitionBucket.DefinitionItem == definition); + foreach (var entry in EntriesWhenNotGroupingByDefinition) + { + if (entry.DefinitionBucket.DefinitionItem == definition) + return true; + } + + return false; } } @@ -152,10 +157,10 @@ private async ValueTask OnEntryFoundAsync( { // Once we can make the new entry, add it to the appropriate list. if (addToEntriesWhenGroupingByDefinition) - EntriesWhenGroupingByDefinition = EntriesWhenGroupingByDefinition.Add(entry); + EntriesWhenGroupingByDefinition.Add(entry); if (addToEntriesWhenNotGroupingByDefinition) - EntriesWhenNotGroupingByDefinition = EntriesWhenNotGroupingByDefinition.Add(entry); + EntriesWhenNotGroupingByDefinition.Add(entry); } CurrentVersionNumber++; diff --git a/src/VisualStudio/Core/Def/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs b/src/VisualStudio/Core/Def/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs index 810b88b7b1154..7524dd91ee1ca 100644 --- a/src/VisualStudio/Core/Def/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs +++ b/src/VisualStudio/Core/Def/FindReferences/Contexts/WithoutReferencesFindUsagesContext.cs @@ -63,8 +63,8 @@ private async Task CreateNoResultsFoundEntryIfNecessaryAsync() lock (Gate) { - EntriesWhenGroupingByDefinition = EntriesWhenGroupingByDefinition.Add(entry); - EntriesWhenNotGroupingByDefinition = EntriesWhenNotGroupingByDefinition.Add(entry); + EntriesWhenGroupingByDefinition.Add(entry); + EntriesWhenNotGroupingByDefinition.Add(entry); CurrentVersionNumber++; } @@ -108,8 +108,8 @@ protected override async ValueTask OnDefinitionFoundWorkerAsync(DefinitionItem d { lock (Gate) { - EntriesWhenGroupingByDefinition = EntriesWhenGroupingByDefinition.AddRange(entries); - EntriesWhenNotGroupingByDefinition = EntriesWhenNotGroupingByDefinition.AddRange(entries); + AddRange(EntriesWhenGroupingByDefinition, entries); + AddRange(EntriesWhenNotGroupingByDefinition, entries); CurrentVersionNumber++; } diff --git a/src/VisualStudio/Core/Def/FindReferences/TableEntriesSnapshot.cs b/src/VisualStudio/Core/Def/FindReferences/TableEntriesSnapshot.cs index 5586c52c73ff8..8c167ff234dc4 100644 --- a/src/VisualStudio/Core/Def/FindReferences/TableEntriesSnapshot.cs +++ b/src/VisualStudio/Core/Def/FindReferences/TableEntriesSnapshot.cs @@ -15,21 +15,14 @@ internal partial class StreamingFindUsagesPresenter // Name of the key used to retireve the whole entry object. internal const string SelfKeyName = "self"; - private class TableEntriesSnapshot : WpfTableEntriesSnapshotBase + private class TableEntriesSnapshot(ImmutableArray entries, int versionNumber) : WpfTableEntriesSnapshotBase { - private readonly int _versionNumber; - - private readonly ImmutableList _entries; - - public TableEntriesSnapshot(ImmutableList entries, int versionNumber) - { - _entries = entries; - _versionNumber = versionNumber; - } + private readonly int _versionNumber = versionNumber; + private readonly ImmutableArray _entries = entries; public override int VersionNumber => _versionNumber; - public override int Count => _entries.Count; + public override int Count => _entries.Length; public override int IndexOf(int currentIndex, ITableEntriesSnapshot newSnapshot) {