Skip to content

Commit

Permalink
Optimize HlslSourceRewriter.VisitIdentifierName
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Dec 6, 2023
1 parent 5973921 commit 785f332
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,11 @@ public sealed override SyntaxNode VisitDefaultExpression(DefaultExpressionSyntax
{
IdentifierNameSyntax updatedNode = (IdentifierNameSyntax)base.VisitIdentifierName(node)!;

if (SemanticModel.For(node).GetOperation(node) is IFieldReferenceOperation operation &&
// Only gather constants directly accessed by name. We can also pre-filter to exclude invocations
// and member access expressions, as those will be handled separately. Doing so avoids unnecessarily
// retrieving semantic information for every identifier, which would otherwise be fairly expensive.
if (node.Parent is not (InvocationExpressionSyntax or MemberAccessExpressionSyntax) &&
SemanticModel.For(node).GetOperation(node) is IFieldReferenceOperation operation &&
operation.Field.IsConst &&
operation.Type!.TypeKind != TypeKind.Enum)
{
Expand Down

0 comments on commit 785f332

Please sign in to comment.