Minor optimization to float literal rewriting

このコミットが含まれているのは:
Sergio Pedri committed 2022-05-29 23:14:25 +02:00
1 親 6c4ae61fbe
コミット f66342d212
2ファイル変更
+14 -4

検索条件に一致するファイルはありません

+7 -2
ファイルの表示
@@ -21,6 +21,11 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters;
/// </summary>
internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
{
/// <summary>
/// An array with the <c>'.'</c> and <c>'E'</c> characters.
/// </summary>
private static readonly char[] FloatLiteralSpecialCharacters = { '.', 'E' };
/// <summary>
/// The <see cref="SemanticModelProvider"/> instance with semantic info on the target syntax tree.
/// </summary>
@@ -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";
}