diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
index 4b3aee1f..d6125b6b 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
@@ -63,7 +63,6 @@
-
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs
index 32b042eb..fea4c8b3 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs
@@ -2,9 +2,9 @@
using System.Globalization;
using System.Linq;
using System.Text;
-using ComputeSharp.__Internals;
using ComputeSharp.D2D1.__Internals;
using ComputeSharp.D2D1.SourceGenerators.Models;
+using ComputeSharp.SourceGeneration.Helpers;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
@@ -216,18 +216,17 @@ partial class ID2D1ShaderGenerator
/// A formatted with the serialized data.
internal static string BuildShaderBytecodeExpressionString(ReadOnlySpan bytecode)
{
- //The estimation is 4 characters per byte (up to "255" in hex), plus ", " to separate sequential values
- using ArrayPoolStringBuilder builder = ArrayPoolStringBuilder.Create(bytecode.Length * 6);
+ using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
- builder.Append(formattedBytes[bytecode[0]]);
+ builder.AddRange(formattedBytes[bytecode[0]].AsSpan());
foreach (byte b in bytecode.Slice(1))
{
- builder.Append(", ");
- builder.Append(formattedBytes[b]);
+ builder.AddRange(", ".AsSpan());
+ builder.AddRange(formattedBytes[b].AsSpan());
}
- return builder.WrittenSpan.ToString();
+ return builder.ToString();
}
}
}
diff --git a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs
index a87e467b..cb98574e 100644
--- a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs
+++ b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableArrayBuilder{T}.cs
@@ -119,7 +119,15 @@ internal ref struct ImmutableArrayBuilder
///
public Writer()
{
- this.array = new T[8];
+ if (typeof(T) == typeof(char))
+ {
+ this.array = new T[1024];
+ }
+ else
+ {
+ this.array = new T[8];
+ }
+
this.index = 0;
}
diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj
index 5942d30d..fde18d60 100644
--- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj
+++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj
@@ -82,7 +82,6 @@
-
diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs
index 37ecf4dc..544c1189 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs
@@ -1,6 +1,7 @@
using System;
using System.Text;
using ComputeSharp.__Internals;
+using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGenerators.Models;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
@@ -237,18 +238,17 @@ partial class IShaderGenerator
/// A formatted with the serialized data.
private static string BuildShaderBytecodeExpressionString(ReadOnlySpan bytecode)
{
- //The estimation is 4 characters per byte (up to "255" in hex), plus ", " to separate sequential values
- using ArrayPoolStringBuilder builder = ArrayPoolStringBuilder.Create(bytecode.Length * 6);
+ using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent();
- builder.Append(formattedBytes[bytecode[0]]);
+ builder.AddRange(formattedBytes[bytecode[0]].AsSpan());
foreach (byte b in bytecode.Slice(1))
{
- builder.Append(", ");
- builder.Append(formattedBytes[b]);
+ builder.AddRange(", ".AsSpan());
+ builder.AddRange(formattedBytes[b].AsSpan());
}
- return builder.WrittenSpan.ToString();
+ return builder.ToString();
}
}
}