Skip to content

Commit b1c46c3

Browse files
committed
Cache the delegate for SA1503BracesMustNotBeOmitted.HandleIfStatement
1 parent d8d53da commit b1c46c3

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1503BracesMustNotBeOmitted.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace StyleCop.Analyzers.LayoutRules
55
{
6+
using System;
67
using System.Collections.Generic;
78
using System.Collections.Immutable;
89
using System.Linq;
@@ -67,6 +68,8 @@ internal class SA1503BracesMustNotBeOmitted : DiagnosticAnalyzer
6768
private static readonly DiagnosticDescriptor Descriptor =
6869
new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.LayoutRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);
6970

71+
private static readonly Action<SyntaxNodeAnalysisContext> IfStatementAction = HandleIfStatement;
72+
7073
/// <inheritdoc/>
7174
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
7275
ImmutableArray.Create(Descriptor);
@@ -77,7 +80,7 @@ public override void Initialize(AnalysisContext context)
7780
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
7881
context.EnableConcurrentExecution();
7982

80-
context.RegisterSyntaxNodeAction(HandleIfStatement, SyntaxKind.IfStatement);
83+
context.RegisterSyntaxNodeAction(IfStatementAction, SyntaxKind.IfStatement);
8184
context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ((DoStatementSyntax)ctx.Node).Statement), SyntaxKind.DoStatement);
8285
context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ((WhileStatementSyntax)ctx.Node).Statement), SyntaxKind.WhileStatement);
8386
context.RegisterSyntaxNodeAction(ctx => CheckChildStatement(ctx, ((ForStatementSyntax)ctx.Node).Statement), SyntaxKind.ForStatement);

0 commit comments

Comments
 (0)