diff --git a/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs b/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs
index 5395f808..8b713980 100644
--- a/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs
+++ b/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs
@@ -68,8 +68,8 @@ public sealed class AutoConstructorGenerator : IIncrementalGenerator
/// The instance for .
public static ConstructorInfo GetData(INamedTypeSymbol structDeclarationSymbol)
{
- using ImmutableArrayBuilder parameters = ImmutableArrayBuilder.Rent();
- using ImmutableArrayBuilder defaulted = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder parameters = new();
+ using ImmutableArrayBuilder defaulted = new();
foreach (IFieldSymbol fieldSymbol in structDeclarationSymbol.GetMembers().OfType())
{
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.EffectId.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.EffectId.cs
index c5715018..71e86996 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.EffectId.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.EffectId.cs
@@ -87,7 +87,7 @@ partial class D2DPixelShaderDescriptorGenerator
string assemblyName = typeSymbol.ContainingAssembly?.Name ?? string.Empty;
- using ImmutableArrayBuilder charBuffer = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder charBuffer = new();
// Format the fully qualified name into a pooled builder to avoid the string allocation
typeSymbol.AppendFullyQualifiedMetadataName(in charBuffer);
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslSource.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslSource.cs
index bf547c42..e6c8ba8e 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslSource.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslSource.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
-using System.Text;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Mappings;
@@ -106,8 +105,8 @@ partial class D2DPixelShaderDescriptorGenerator
out ImmutableArray<(string Name, string HlslType)> valueFields,
out ImmutableArray<(string Name, string HlslType, int Index)> resourceTextureFields)
{
- using ImmutableArrayBuilder<(string, string)> values = ImmutableArrayBuilder<(string, string)>.Rent();
- using ImmutableArrayBuilder<(string, string, int)> resourceTextures = ImmutableArrayBuilder<(string, string, int)>.Rent();
+ using ImmutableArrayBuilder<(string, string)> values = new();
+ using ImmutableArrayBuilder<(string, string, int)> resourceTextures = new();
foreach (IFieldSymbol fieldSymbol in structDeclarationSymbol.GetMembers().OfType())
{
@@ -199,7 +198,7 @@ partial class D2DPixelShaderDescriptorGenerator
IDictionary constantDefinitions,
out bool needsD2D1RequiresScenePosition)
{
- using ImmutableArrayBuilder<(string, string, string?)> builder = ImmutableArrayBuilder<(string, string, string?)>.Rent();
+ using ImmutableArrayBuilder<(string, string, string?)> builder = new();
needsD2D1RequiresScenePosition = false;
@@ -280,7 +279,7 @@ partial class D2DPixelShaderDescriptorGenerator
string? entryPoint = null;
- using ImmutableArrayBuilder<(string, string)> methods = ImmutableArrayBuilder<(string, string)>.Rent();
+ using ImmutableArrayBuilder<(string, string)> methods = new();
needsD2D1RequiresScenePosition = false;
@@ -358,7 +357,7 @@ partial class D2DPixelShaderDescriptorGenerator
/// A sequence of discovered constants to declare in the shader.
private static ImmutableArray<(string Name, string Value)> GetDefinedConstants(IReadOnlyDictionary constantDefinitions)
{
- using ImmutableArrayBuilder<(string, string)> builder = ImmutableArrayBuilder<(string, string)>.Rent();
+ using ImmutableArrayBuilder<(string, string)> builder = new();
foreach (KeyValuePair constant in constantDefinitions)
{
@@ -385,7 +384,7 @@ partial class D2DPixelShaderDescriptorGenerator
IEnumerable types,
IReadOnlyDictionary instanceMethods)
{
- using ImmutableArrayBuilder<(string, string)> builder = ImmutableArrayBuilder<(string, string)>.Rent();
+ using ImmutableArrayBuilder<(string, string)> builder = new();
IReadOnlyCollection invalidTypes;
@@ -527,17 +526,17 @@ partial class D2DPixelShaderDescriptorGenerator
ImmutableArray inputComplexIndices,
bool requiresScenePosition)
{
- StringBuilder hlslBuilder = new();
+ using ImmutableArrayBuilder hlslBuilder = new();
void AppendLF()
{
- _ = hlslBuilder.Append('\n');
+ hlslBuilder.Add('\n');
}
void AppendLineAndLF(string text)
{
- _ = hlslBuilder.Append(text);
- _ = hlslBuilder.Append('\n');
+ hlslBuilder.AddRange(text.AsSpan());
+ hlslBuilder.Add('\n');
}
// Header
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.Syntax.cs
index c2a6b125..e90e3eae 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.Syntax.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.Syntax.cs
@@ -71,7 +71,7 @@ partial class D2DPixelShaderDescriptorGenerator
using (writer.WriteBlock())
{
- using ImmutableArrayBuilder> dataMembers = ImmutableArrayBuilder>.Rent();
+ using ImmutableArrayBuilder> dataMembers = new();
RegisterAdditionalDataMemberSyntax(info, dataMembers);
ResourceTextureDescriptions.RegisterAdditionalDataMemberSyntax(info, dataMembers);
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.cs
index f6786a19..22b79d36 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputDescriptions.cs
@@ -30,7 +30,7 @@ partial class D2DPixelShaderDescriptorGenerator
{
int inputCount = 0;
- using ImmutableArrayBuilder inputDescriptionsBuilder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder inputDescriptionsBuilder = new();
foreach (AttributeData attributeData in structDeclarationSymbol.GetAttributes())
{
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputTypes.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputTypes.cs
index 74e902d8..8e8be4b3 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputTypes.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.InputTypes.cs
@@ -41,8 +41,8 @@ partial class D2DPixelShaderDescriptorGenerator
inputCount = 0;
- using ImmutableArrayBuilder inputSimpleIndicesBuilder = ImmutableArrayBuilder.Rent();
- using ImmutableArrayBuilder inputComplexIndicesBuilder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder inputSimpleIndicesBuilder = new();
+ using ImmutableArrayBuilder inputComplexIndicesBuilder = new();
foreach (AttributeData attributeData in structDeclarationSymbol.GetAttributes())
{
@@ -154,7 +154,7 @@ partial class D2DPixelShaderDescriptorGenerator
}
// Build the combined input types list now that inputs have been validated
- using ImmutableArrayBuilder combinedBuilder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder combinedBuilder = new();
for (int i = 0; i < inputCount; i++)
{
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.LoadConstantBuffer.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.LoadConstantBuffer.cs
index b950c73b..8b644d65 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.LoadConstantBuffer.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.LoadConstantBuffer.cs
@@ -124,7 +124,7 @@ partial class D2DPixelShaderDescriptorGenerator
// each row needs to be at a multiple of 16 bytes (a float4 register).
if (HlslKnownTypes.IsNonLinearMatrixType(typeName, out string? elementName, out int rows, out int columns))
{
- using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder builder = new();
for (int j = 0; j < rows; j++)
{
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ResourceTextureDescriptions.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ResourceTextureDescriptions.cs
index 6282b606..51618a43 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ResourceTextureDescriptions.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ResourceTextureDescriptions.cs
@@ -31,7 +31,7 @@ partial class D2DPixelShaderDescriptorGenerator
int inputCount,
out ImmutableArray resourceTextureDescriptions)
{
- using ImmutableArrayBuilder<(int? Index, int Rank)> resourceTextureInfos = ImmutableArrayBuilder<(int? Index, int Rank)>.Rent();
+ using ImmutableArrayBuilder<(int? Index, int Rank)> resourceTextureInfos = new();
foreach (IFieldSymbol fieldSymbol in structDeclarationSymbol.GetMembers().OfType())
{
@@ -72,7 +72,7 @@ partial class D2DPixelShaderDescriptorGenerator
}
// Extract the resource texture descriptions for the rest of the pipeline
- using (ImmutableArrayBuilder resourceTextureDescriptionsBuilder = ImmutableArrayBuilder.Rent())
+ using (ImmutableArrayBuilder resourceTextureDescriptionsBuilder = new())
{
foreach ((int? index, int rank) in resourceTextureInfos.WrittenSpan)
{
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs
index 7986307b..d6ca1bc2 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs
@@ -76,7 +76,7 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene
token.ThrowIfCancellationRequested();
- using ImmutableArrayBuilder diagnostics = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder diagnostics = new();
// LoadDispatchData() info
ImmutableArray fieldInfos = LoadConstantBuffer.GetInfo(
@@ -201,7 +201,7 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene
// Generate the source files, if any
context.RegisterSourceOutput(outputInfo, static (context, item) =>
{
- using ImmutableArrayBuilder> declaredMembers = ImmutableArrayBuilder>.Rent();
+ using ImmutableArrayBuilder> declaredMembers = new();
declaredMembers.Add(EffectId.WriteSyntax);
declaredMembers.Add(EffectMetadata.WriteEffectDisplayNameSyntax);
@@ -224,15 +224,15 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene
declaredMembers.Add(CreateFromConstantBuffer.WriteSyntax);
declaredMembers.Add(LoadConstantBuffer.WriteSyntax);
- using ImmutableArrayBuilder> additionalTypes = ImmutableArrayBuilder>.Rent();
- using ImmutableHashSetBuilder usingDirectives = ImmutableHashSetBuilder.Rent();
+ using ImmutableArrayBuilder> additionalTypes = new();
+ using ImmutableHashSetBuilder usingDirectives = new();
LoadConstantBuffer.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
InputDescriptions.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
InputTypes.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
HlslBytecode.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
- using IndentedTextWriter writer = IndentedTextWriter.Rent();
+ using IndentedTextWriter writer = new();
item.Hierarchy.WriteSyntax(
state: item,
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs
index fde55cf1..2d4bffd6 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.cs
@@ -35,7 +35,7 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
MethodDeclarationSyntax methodDeclaration = (MethodDeclarationSyntax)context.TargetNode;
IMethodSymbol methodSymbol = (IMethodSymbol)context.TargetSymbol;
- using ImmutableArrayBuilder diagnostics = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder diagnostics = new();
// Get the remaining info for the current shader
ImmutableArray modifiers = methodDeclaration.Modifiers.Select(token => (ushort)token.Kind()).ToImmutableArray();
@@ -89,7 +89,7 @@ public sealed partial class D2DPixelShaderSourceGenerator : IIncrementalGenerato
// Generate the shader bytecode methods
context.RegisterSourceOutput(outputInfo, static (context, item) =>
{
- using IndentedTextWriter writer = IndentedTextWriter.Rent();
+ using IndentedTextWriter writer = new();
item.Hierarchy.WriteSyntax(
state: item,
diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxFormattingHelper.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxFormattingHelper.cs
index d8d0fd01..adb62bf4 100644
--- a/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxFormattingHelper.cs
+++ b/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxFormattingHelper.cs
@@ -103,7 +103,7 @@ internal static class SyntaxFormattingHelper
///
public static string BuildByteArrayInitializationExpressionString(ReadOnlySpan bytecode)
{
- using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder builder = new();
builder.AddRange(FormattedBytes[bytecode[0]].AsSpan());
diff --git a/src/ComputeSharp.SourceGeneration/Extensions/IFieldSymbolExtensions.cs b/src/ComputeSharp.SourceGeneration/Extensions/IFieldSymbolExtensions.cs
index 92c3c869..ee9cdefe 100644
--- a/src/ComputeSharp.SourceGeneration/Extensions/IFieldSymbolExtensions.cs
+++ b/src/ComputeSharp.SourceGeneration/Extensions/IFieldSymbolExtensions.cs
@@ -16,7 +16,7 @@ internal static class IFieldSymbolExtensions
/// The fully qualified metadata name for .
public static string GetFullyQualifiedMetadataName(this IFieldSymbol symbol)
{
- using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder builder = new();
symbol.ContainingType!.AppendFullyQualifiedMetadataName(in builder);
diff --git a/src/ComputeSharp.SourceGeneration/Extensions/IMethodSymbolExtensions.cs b/src/ComputeSharp.SourceGeneration/Extensions/IMethodSymbolExtensions.cs
index fc01872c..8325850e 100644
--- a/src/ComputeSharp.SourceGeneration/Extensions/IMethodSymbolExtensions.cs
+++ b/src/ComputeSharp.SourceGeneration/Extensions/IMethodSymbolExtensions.cs
@@ -17,7 +17,7 @@ internal static class IMethodSymbolExtensions
/// The fully qualified metadata name for .
public static string GetFullyQualifiedMetadataName(this IMethodSymbol symbol, bool includeParameters = false)
{
- using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder builder = new();
symbol.ContainingType!.AppendFullyQualifiedMetadataName(in builder);
diff --git a/src/ComputeSharp.SourceGeneration/Extensions/IPropertySymbolExtensions.cs b/src/ComputeSharp.SourceGeneration/Extensions/IPropertySymbolExtensions.cs
index 57fc7661..d77f7c7b 100644
--- a/src/ComputeSharp.SourceGeneration/Extensions/IPropertySymbolExtensions.cs
+++ b/src/ComputeSharp.SourceGeneration/Extensions/IPropertySymbolExtensions.cs
@@ -16,7 +16,7 @@ internal static class IPropertySymbolExtensions
/// The fully qualified metadata name for .
public static string GetFullyQualifiedMetadataName(this IPropertySymbol symbol)
{
- using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder builder = new();
symbol.ContainingType!.AppendFullyQualifiedMetadataName(in builder);
diff --git a/src/ComputeSharp.SourceGeneration/Extensions/ITypeSymbolExtensions.cs b/src/ComputeSharp.SourceGeneration/Extensions/ITypeSymbolExtensions.cs
index 5149f647..2169baa3 100644
--- a/src/ComputeSharp.SourceGeneration/Extensions/ITypeSymbolExtensions.cs
+++ b/src/ComputeSharp.SourceGeneration/Extensions/ITypeSymbolExtensions.cs
@@ -17,7 +17,7 @@ internal static class ITypeSymbolExtensions
/// Whether has a full name equals to .
public static bool HasFullyQualifiedMetadataName(this ITypeSymbol symbol, string name)
{
- using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder builder = new();
symbol.AppendFullyQualifiedMetadataName(in builder);
@@ -50,7 +50,7 @@ internal static class ITypeSymbolExtensions
/// The fully qualified metadata name for .
public static string GetFullyQualifiedMetadataName(this ITypeSymbol symbol)
{
- using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder builder = new();
symbol.AppendFullyQualifiedMetadataName(in builder);
diff --git a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs
index aa1d495a..9ec626c1 100644
--- a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs
+++ b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs
@@ -25,21 +25,11 @@ internal struct ImmutableArrayBuilder : IDisposable
private Writer? writer;
///
- /// Creates a value with a pooled underlying data writer.
+ /// Creates a new object.
///
- /// A instance to write data to.
- public static ImmutableArrayBuilder Rent()
+ public ImmutableArrayBuilder()
{
- return new(SharedObjectPool.Allocate());
- }
-
- ///
- /// Creates a new object with the specified parameters.
- ///
- /// The target data writer to use.
- private ImmutableArrayBuilder(Writer writer)
- {
- this.writer = writer;
+ this.writer = SharedObjectPool.Allocate();
}
///
@@ -89,6 +79,12 @@ internal struct ImmutableArrayBuilder : IDisposable
this.writer!.AddRange(items);
}
+ ///
+ public readonly void Clear()
+ {
+ this.writer!.Clear();
+ }
+
///
/// Inserts an item to the builder at the specified index.
///
@@ -203,6 +199,12 @@ internal struct ImmutableArrayBuilder : IDisposable
this.index += items.Length;
}
+ ///
+ public void Clear(ReadOnlySpan items)
+ {
+ this.index = 0;
+ }
+
///
public void Insert(int index, T item)
{
@@ -227,7 +229,9 @@ internal struct ImmutableArrayBuilder : IDisposable
///
public void Clear()
{
- if (typeof(T) != typeof(char))
+ if (typeof(T) != typeof(byte) &&
+ typeof(T) != typeof(char) &&
+ typeof(T) != typeof(int))
{
this.array.AsSpan(0, this.index).Clear();
}
diff --git a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs
index f9faaaca..e96aa224 100644
--- a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs
+++ b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs
@@ -27,21 +27,11 @@ internal struct ImmutableHashSetBuilder : IDisposable
private HashSet? set;
///
- /// Creates a value with a pooled underlying data writer.
+ /// Creates a new object.
///
- /// A instance to write data to.
- public static ImmutableHashSetBuilder Rent()
+ public ImmutableHashSetBuilder()
{
- return new(SharedObjectPool.Allocate());
- }
-
- ///
- /// Creates a new object with the specified parameters.
- ///
- /// The target instance to use.
- private ImmutableHashSetBuilder(HashSet set)
- {
- this.set = set;
+ this.set = SharedObjectPool.Allocate();
}
///
diff --git a/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs b/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs
index dd28647d..37c51870 100644
--- a/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs
+++ b/src/ComputeSharp.SourceGeneration/Helpers/IndentedTextWriter.cs
@@ -45,21 +45,11 @@ internal sealed class IndentedTextWriter : IDisposable
private string[] availableIndentations;
///
- /// Creates an instance with a pooled underlying data writer.
+ /// Creates a new object.
///
- /// An instance to write data to.
- public static IndentedTextWriter Rent()
+ public IndentedTextWriter()
{
- return new(ImmutableArrayBuilder.Rent());
- }
-
- ///
- /// Creates a new object with the specified parameters.
- ///
- /// The target instance to use.
- private IndentedTextWriter(ImmutableArrayBuilder builder)
- {
- this.builder = builder;
+ this.builder = new ImmutableArrayBuilder();
this.currentIndentationLevel = 0;
this.currentIndentation = "";
this.availableIndentations = new string[4];
diff --git a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs
index 1ce487c3..50c8d05f 100644
--- a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs
+++ b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs
@@ -24,7 +24,7 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
/// A instance describing .
public static HierarchyInfo From(INamedTypeSymbol typeSymbol)
{
- using ImmutableArrayBuilder hierarchy = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder hierarchy = new();
for (INamedTypeSymbol? parent = typeSymbol;
parent is not null;
@@ -115,7 +115,7 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
/// The fully qualified type name for the current instance.
public string GetFullyQualifiedTypeName()
{
- using ImmutableArrayBuilder fullyQualifiedTypeName = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder fullyQualifiedTypeName = new();
fullyQualifiedTypeName.AddRange("global::".AsSpan());
fullyQualifiedTypeName.AddRange(Namespace.AsSpan());
diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs
index 3b693127..19e1d07f 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs
@@ -85,7 +85,7 @@ partial class IShaderGenerator
/// The series of statements to build the HLSL source to compile to execute the current shader.
private static ImmutableArray GenerateRenderMethodBody(HlslShaderSourceInfo hlslSourceInfo, int hierarchyDepth)
{
- using ImmutableArrayBuilder statements = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder statements = new();
StringBuilder textBuilder = new();
int capturedDelegates = 0;
diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs
index d8fbbae0..fbadb447 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
-using System.Text;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Mappings;
@@ -106,8 +105,8 @@ partial class IShaderGenerator
ICollection types,
bool isComputeShader)
{
- using ImmutableArrayBuilder<(string, string, string)> resources = ImmutableArrayBuilder<(string, string, string)>.Rent();
- using ImmutableArrayBuilder<(string, string)> values = ImmutableArrayBuilder<(string, string)>.Rent();
+ using ImmutableArrayBuilder<(string, string, string)> resources = new();
+ using ImmutableArrayBuilder<(string, string)> values = new();
bool hlslResourceFound = false;
@@ -200,7 +199,7 @@ partial class IShaderGenerator
ICollection discoveredTypes,
IDictionary constantDefinitions)
{
- using ImmutableArrayBuilder<(string, string, string?)> builder = ImmutableArrayBuilder<(string, string, string?)>.Rent();
+ using ImmutableArrayBuilder<(string, string, string?)> builder = new();
foreach (FieldDeclarationSyntax fieldDeclaration in structDeclaration.Members.OfType())
{
@@ -264,7 +263,7 @@ partial class IShaderGenerator
INamedTypeSymbol structDeclarationSymbol,
ICollection types)
{
- using ImmutableArrayBuilder<(string, string, int?)> builder = ImmutableArrayBuilder<(string, string, int?)>.Rent();
+ using ImmutableArrayBuilder<(string, string, int?)> builder = new();
foreach (IFieldSymbol fieldSymbol in structDeclarationSymbol.GetMembers().OfType())
{
@@ -338,7 +337,7 @@ partial class IShaderGenerator
where syntaxNode.IsKind(SyntaxKind.MethodDeclaration)
select (MethodDeclarationSyntax)syntaxNode).ToImmutableArray();
- using ImmutableArrayBuilder<(string, string)> methods = ImmutableArrayBuilder<(string, string)>.Rent();
+ using ImmutableArrayBuilder<(string, string)> methods = new();
string? entryPoint = null;
bool isSamplerUsed = false;
@@ -426,7 +425,7 @@ partial class IShaderGenerator
/// A sequence of discovered constants to declare in the shader.
internal static ImmutableArray<(string Name, string Value)> GetDefinedConstants(IReadOnlyDictionary constantDefinitions)
{
- using ImmutableArrayBuilder<(string, string)> builder = ImmutableArrayBuilder<(string, string)>.Rent();
+ using ImmutableArrayBuilder<(string, string)> builder = new();
foreach (KeyValuePair constant in constantDefinitions)
{
@@ -453,7 +452,7 @@ partial class IShaderGenerator
IEnumerable types,
IReadOnlyDictionary instanceMethods)
{
- using ImmutableArrayBuilder<(string, string)> builder = ImmutableArrayBuilder<(string, string)>.Rent();
+ using ImmutableArrayBuilder<(string, string)> builder = new();
IReadOnlyCollection invalidTypes;
@@ -566,38 +565,37 @@ partial class IShaderGenerator
bool isComputeShader,
string? implicitTextureType,
bool isSamplerUsed,
-
string executeMethod)
{
- StringBuilder hlslBuilder = new();
+ using ImmutableArrayBuilder hlslBuilder = new();
void AppendLF()
{
- _ = hlslBuilder.Append('\n');
+ hlslBuilder.Add('\n');
}
void AppendLine(string text)
{
- _ = hlslBuilder.Append(text);
+ hlslBuilder.AddRange(text.AsSpan());
}
void AppendLineAndLF(string text)
{
- _ = hlslBuilder.Append(text);
- _ = hlslBuilder.Append('\n');
+ hlslBuilder.AddRange(text.AsSpan());
+ hlslBuilder.Add('\n');
}
void AppendCharacterAndLF(char c)
{
- _ = hlslBuilder.Append(c);
- _ = hlslBuilder.Append('\n');
+ hlslBuilder.Add(c);
+ hlslBuilder.Add('\n');
}
string FlushText()
{
string text = hlslBuilder.ToString();
- _ = hlslBuilder.Clear();
+ hlslBuilder.Clear();
return text;
}
diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs
index 7a52ad3f..d73836c6 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs
@@ -68,7 +68,7 @@ partial class IShaderGenerator
int resourceCount,
int root32BitConstantsCount)
{
- using ImmutableArrayBuilder statements = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder statements = new();
// global::System.Span span0 = stackalloc uint[];
statements.Add(
diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs
index d028a75b..6a3cba0f 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs
@@ -149,7 +149,7 @@ partial class IShaderGenerator
// each row needs to be at a multiple of 16 bytes (a float4 register).
if (HlslKnownTypes.IsNonLinearMatrixType(typeName, out string? elementName, out int rows, out int columns))
{
- using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder builder = new();
for (int j = 0; j < rows; j++)
{
diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs
index 9af3d88d..8850cb37 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.Syntax.cs
@@ -55,7 +55,7 @@ partial class IShaderGenerator
/// The sequence of instances to load shader dispatch data.
private static ImmutableArray GetDispatchMetadataLoadingStatements(DispatchMetadataInfo metadataInfo)
{
- using ImmutableArrayBuilder statements = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder statements = new();
// global::System.Span span0 = stackalloc byte[5];
statements.Add(
diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.cs
index a611cfd5..6822c017 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchMetadataMethod.cs
@@ -27,7 +27,7 @@ partial class IShaderGenerator
bool isSamplerUsed,
ImmutableArray capturedFields)
{
- using ImmutableArrayBuilder descriptors = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder descriptors = new();
int constantBufferOffset = 1;
int readOnlyResourceOffset = 0;
diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs
index de5aeb12..d5f11f45 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs
@@ -55,7 +55,7 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
return default;
}
- using ImmutableArrayBuilder diagnostics = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder diagnostics = new();
// GetDispatchId() info
ImmutableArray dispatchIdInfo = GetDispatchId.GetInfo(typeSymbol);
diff --git a/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs b/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs
index 21297442..1a97cf1f 100644
--- a/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs
+++ b/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs
@@ -78,7 +78,7 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
IMethodSymbol methodSymbol,
out ImmutableArray diagnostics)
{
- using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
+ using ImmutableArrayBuilder builder = new();
// We need to sets to track all discovered custom types and static methods
HashSet discoveredTypes = new(SymbolEqualityComparer.Default);
@@ -136,7 +136,7 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
.NormalizeWhitespace(eol: "\n")
.ToFullString();
- using ImmutableArrayBuilder<(string, string)> methods = ImmutableArrayBuilder<(string, string)>.Rent();
+ using ImmutableArrayBuilder<(string, string)> methods = new();
// Emit the extracted local functions
foreach (KeyValuePair localFunction in shaderSourceRewriter.LocalFunctions)