From f66342d21256b7c5a24164198a25a7705101579d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 29 May 2022 23:14:25 +0200 Subject: [PATCH] Minor optimization to float literal rewriting --- .../SyntaxRewriters/HlslSourceRewriter.cs | 9 +++++++-- .../SyntaxRewriters/HlslSourceRewriter.cs | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs index 0e43e9f7..af78bc83 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs @@ -21,6 +21,11 @@ namespace ComputeSharp.D2D1.SourceGenerators.SyntaxRewriters; /// internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter { + /// + /// An array with the '.' and 'E' characters. + /// + private static readonly char[] FloatLiteralSpecialCharacters = { '.', 'E' }; + /// /// The instance with semantic info on the target syntax tree. /// @@ -195,7 +200,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter string literal = updatedNode.Token.ValueText; // If the numeric literal is neither a decimal nor an exponential, add the ".0" suffix - if (literal.IndexOfAny(new[] { '.', 'E' }) == -1) + if (literal.IndexOfAny(FloatLiteralSpecialCharacters) == -1) { literal += ".0"; } @@ -208,7 +213,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter // If the numeric literal is neither a decimal nor an exponential, add the ".0L" suffix. // This is necessary because otherwise integer literals would actually be of type long. - if (literal.IndexOfAny(new[] { '.', 'E' }) == -1) + if (literal.IndexOfAny(FloatLiteralSpecialCharacters) == -1) { literal += ".0L"; } diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs index 757b8f33..215daa8b 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs @@ -21,6 +21,11 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters; /// internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter { + /// + /// An array with the '.' and 'E' characters. + /// + private static readonly char[] FloatLiteralSpecialCharacters = { '.', 'E' }; + /// /// The instance with semantic info on the target syntax tree. /// @@ -200,7 +205,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter string literal = updatedNode.Token.ValueText; // If the numeric literal is neither a decimal nor an exponential, add the ".0" suffix - if (literal.IndexOfAny(new[] { '.', 'E' }) == -1) + if (literal.IndexOfAny(FloatLiteralSpecialCharacters) == -1) { literal += ".0"; } @@ -213,7 +218,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter // If the numeric literal is neither a decimal nor an exponential, add the ".0L" suffix. // This is necessary because otherwise integer literals would actually be of type long. - if (literal.IndexOfAny(new[] { '.', 'E' }) == -1) + if (literal.IndexOfAny(FloatLiteralSpecialCharacters) == -1) { literal += ".0L"; }