提交 62018870 编写于 作者: J Jason Malinowski

Use PooledHashSet to avoid extra allocations

Many of these can be called fairly often, so this avoids allocations in
the common case we don't refresh anything.
上级 441d055d
......@@ -13,6 +13,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Microsoft.CodeAnalysis.Text;
......@@ -1421,7 +1422,7 @@ public void AddProjectOutputPath(ProjectId projectId, string outputPath)
private void ConvertMetadataReferencesToProjectReferences_NoLock(ProjectId projectId, string outputPath)
{
var modifiedSolution = this.CurrentSolution;
var projectIdsChanged = new HashSet<ProjectId>();
var projectIdsChanged = PooledHashSet<ProjectId>.GetInstance();
foreach (var projectIdToRetarget in this.CurrentSolution.ProjectIds)
{
......@@ -1452,6 +1453,7 @@ private void ConvertMetadataReferencesToProjectReferences_NoLock(ProjectId proje
}
SetSolutionAndRaiseWorkspaceChanged_NoLock(modifiedSolution, projectIdsChanged);
projectIdsChanged.Free();
}
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/31306",
......@@ -1489,7 +1491,7 @@ private bool CanConvertMetadataReferenceToProjectReference(ProjectId projectIdWi
private void ConvertProjectReferencesToMetadataReferences_NoLock(ProjectId projectId, string outputPath)
{
var modifiedSolution = this.CurrentSolution;
var projectIdsChanged = new HashSet<ProjectId>();
var projectIdsChanged = PooledHashSet<ProjectId>.GetInstance();
foreach (var projectIdToRetarget in this.CurrentSolution.ProjectIds)
{
......@@ -1521,6 +1523,7 @@ private void ConvertProjectReferencesToMetadataReferences_NoLock(ProjectId proje
}
SetSolutionAndRaiseWorkspaceChanged_NoLock(modifiedSolution, projectIdsChanged);
projectIdsChanged.Free();
}
public ProjectReference TryCreateConvertedProjectReference(ProjectId referencingProject, string path, MetadataReferenceProperties properties)
......@@ -1634,7 +1637,7 @@ private void RefreshMetadataReferencesForFile(object sender, string fullFilePath
lock (_gate)
{
var newSolution = CurrentSolution;
var changedProjectIds = new HashSet<ProjectId>();
var changedProjectIds = PooledHashSet<ProjectId>.GetInstance();
foreach (var project in CurrentSolution.Projects)
{
......@@ -1662,6 +1665,7 @@ private void RefreshMetadataReferencesForFile(object sender, string fullFilePath
}
SetSolutionAndRaiseWorkspaceChanged_NoLock(newSolution, changedProjectIds);
changedProjectIds.Free();
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册