From b094a81e3204a4319f1873cced11fdbe88d6c438 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 28 Aug 2021 18:47:41 +0200 Subject: [PATCH] Minor optimizations to string building APIs --- ...aderMethodSourceAttribute.HlslGeneration.cs | 18 +++++++++++------- .../__Internals/ArrayPoolStringBuilder.cs | 11 +++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/ComputeSharp/Core/Attributes/__Internals/ShaderMethodSourceAttribute.HlslGeneration.cs b/src/ComputeSharp/Core/Attributes/__Internals/ShaderMethodSourceAttribute.HlslGeneration.cs index be523c2c..2018643a 100644 --- a/src/ComputeSharp/Core/Attributes/__Internals/ShaderMethodSourceAttribute.HlslGeneration.cs +++ b/src/ComputeSharp/Core/Attributes/__Internals/ShaderMethodSourceAttribute.HlslGeneration.cs @@ -17,7 +17,11 @@ namespace ComputeSharp.__Internals { if (mapping.Add(constant.Key)) { - builder.Append($"#define {constant.Key} {constant.Value}\n"); + builder.Append("#define "); + builder.Append(constant.Key); + builder.Append(' '); + builder.Append(constant.Value); + builder.Append('\n'); } } } @@ -33,9 +37,9 @@ namespace ComputeSharp.__Internals { if (mapping.Add(type.Key)) { - builder.Append("\n"); + builder.Append('\n'); builder.Append(type.Value); - builder.Append("\n"); + builder.Append('\n'); } } } @@ -51,9 +55,9 @@ namespace ComputeSharp.__Internals { if (mapping.Add(method.Key)) { - builder.Append("\n"); + builder.Append('\n'); builder.Append(method.Key); - builder.Append("\n"); + builder.Append('\n'); } } } @@ -69,9 +73,9 @@ namespace ComputeSharp.__Internals { if (mapping.Remove(method.Key)) { - builder.Append("\n"); + builder.Append('\n'); builder.Append(method.Value); - builder.Append("\n"); + builder.Append('\n'); } } } diff --git a/src/ComputeSharp/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs b/src/ComputeSharp/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs index 1774dee3..a72d2f1f 100644 --- a/src/ComputeSharp/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs +++ b/src/ComputeSharp/Shaders/Translation/__Internals/ArrayPoolStringBuilder.cs @@ -48,6 +48,17 @@ namespace ComputeSharp.__Internals get => new(this.array, 0, this.index); } + /// + /// Appends the input character to the current buffer. + /// + /// The input character to write. + public void Append(char value) + { + EnsureCapacity(1); + + this.array[this.index++] = value; + } + /// /// Appends the input sequence of characters to the current buffer. ///