Skip to content

Commit 46dbf1e

Browse files
committed
Use array builder pools
1 parent baaddfa commit 46dbf1e

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/Compiler/Microsoft.NET.Sdk.Razor.SourceGenerators/Microsoft.NET.Sdk.Razor.SourceGenerators.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22+
<ProjectReference Include="..\..\Shared\Microsoft.AspNetCore.Razor.Utilities.Shared\Microsoft.AspNetCore.Razor.Utilities.Shared.csproj" />
2223
<ProjectReference Include="..\Microsoft.AspNetCore.Mvc.Razor.Extensions\src\Microsoft.AspNetCore.Mvc.Razor.Extensions.csproj" />
2324
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.Language\src\Microsoft.AspNetCore.Razor.Language.csproj" />
2425
<ProjectReference Include="..\Microsoft.CodeAnalysis.Razor\src\Microsoft.CodeAnalysis.Razor.csproj" />

src/Compiler/Microsoft.NET.Sdk.Razor.SourceGenerators/RazorSourceGenerator.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.IO;
88
using System.Linq;
99
using Microsoft.AspNetCore.Razor.Language;
10+
using Microsoft.AspNetCore.Razor.PooledObjects;
1011
using Microsoft.CodeAnalysis;
1112
using Microsoft.CodeAnalysis.CSharp;
1213
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -185,7 +186,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
185186
var tagHelperFeature = new StaticCompilationTagHelperFeature();
186187
var discoveryProjectEngine = GetDiscoveryProjectEngine(compilation.References.ToImmutableArray(), tagHelperFeature);
187188

188-
var descriptors = ImmutableArray.CreateBuilder<TagHelperDescriptor>();
189+
using var pool = ArrayBuilderPool<TagHelperDescriptor>.GetPooledObject(out var descriptors);
189190
tagHelperFeature.Compilation = compilation;
190191
foreach (var reference in compilation.References)
191192
{
@@ -212,8 +213,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
212213
return ImmutableArray<TagHelperDescriptor>.Empty;
213214
}
214215

215-
var allTagHelpers = ImmutableArray.CreateBuilder<TagHelperDescriptor>(count);
216-
allTagHelpers.AddRange(tagHelpersFromCompilation);
216+
using var pool = ArrayBuilderPool<TagHelperDescriptor>.GetPooledObject(out var allTagHelpers);
217+
allTagHelpers.AddRange(tagHelpersFromCompilation);
217218
allTagHelpers.AddRange(tagHelpersFromReferences);
218219
allTagHelpers.AddRange(tagHelpersFromComponents);
219220

src/Compiler/Microsoft.NET.Sdk.Razor.SourceGenerators/StaticCompilationTagHelperFeature.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Immutable;
66
using System.Linq;
77
using Microsoft.AspNetCore.Razor.Language;
8+
using Microsoft.AspNetCore.Razor.PooledObjects;
89
using Microsoft.CodeAnalysis;
910
using Microsoft.CodeAnalysis.Razor;
1011

@@ -21,8 +22,8 @@ public ImmutableArray<TagHelperDescriptor> GetDescriptors()
2122
return ImmutableArray<TagHelperDescriptor>.Empty;
2223
}
2324

24-
var results = ImmutableArray.CreateBuilder<TagHelperDescriptor>();
25-
var context = TagHelperDescriptorProviderContext.Create(results);
25+
using var pool = ArrayBuilderPool<TagHelperDescriptor>.GetPooledObject(out var results);
26+
var context = TagHelperDescriptorProviderContext.Create(results);
2627
context.SetCompilation(Compilation);
2728
if (TargetSymbol is not null)
2829
{

0 commit comments

Comments
 (0)