Skip to content

Commit 1e80048

Browse files
nareshjoNaresh Joshi
andauthored
Reduce allocation in GetNuGetProjects by providing capacity for List (#7050)
Co-authored-by: Naresh Joshi <[email protected]>
1 parent ced2893 commit 1e80048

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Projects/ProjectSystemCache.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,13 @@ public IReadOnlyList<NuGetProject> GetNuGetProjects()
182182

183183
try
184184
{
185-
return _primaryCache
186-
.Select(kv => kv.Value.NuGetProject)
187-
.ToList();
185+
List<NuGetProject> result = new List<NuGetProject>(_primaryCache.Count);
186+
foreach (var kv in _primaryCache)
187+
{
188+
result.Add(kv.Value.NuGetProject);
189+
}
190+
191+
return result;
188192
}
189193
finally
190194
{

0 commit comments

Comments
 (0)