Skip to content

Commit

Permalink
short-circuit calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb committed Dec 23, 2024
1 parent fd8351f commit d9ef886
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,30 @@ public override void AnalyzeCompilation(CompilationStartAnalysisContext context,
// scope out and see if there are any other stash calls inside the same branch
var invocationParent = invocationExpr.DescendantNodes();

DiagnoseSyntaxNodes(invocationParent, semanticModel, stashMethod, ctx);
DiagnoseSyntaxNodes(invocationParent.ToArray(), semanticModel, stashMethod, ctx);
}



}, SyntaxKind.InvocationExpression);
}

private static void DiagnoseSyntaxNodes(IEnumerable<SyntaxNode> invocationParent, SemanticModel semanticModel,
private static void DiagnoseSyntaxNodes(IReadOnlyList<SyntaxNode> invocationParent, SemanticModel semanticModel,
IMethodSymbol stashMethod, SyntaxNodeAnalysisContext ctx)
{
// Find all "Stash.Stash()" calls in the method
var stashCalls = invocationParent
.OfType<InvocationExpressionSyntax>()
.Where(invocation => IsStashInvocation(semanticModel, invocation, stashMethod));
.Where(invocation => IsStashInvocation(semanticModel, invocation, stashMethod)).ToArray();

// aren't enough calls to merit further analysis
if (stashCalls.Length < 2)
return;

// Group calls by their parent block
var callsGroupedByBlock = stashCalls
.GroupBy(GetContainingBlock)
.Where(group => group.Key != null);
.Where(group => group.Key != null).ToArray();

foreach (var group in callsGroupedByBlock)
{
Expand Down Expand Up @@ -99,7 +103,7 @@ private static void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context,
var stashMethod = akkaContext.AkkaCore.Actor.IStash.Stash!;

var invocationParent = methodDeclaration.DescendantNodes();
DiagnoseSyntaxNodes(invocationParent, semanticModel, stashMethod, context);
DiagnoseSyntaxNodes(invocationParent.ToArray(), semanticModel, stashMethod, context);
}

private static bool IsStashInvocation(SemanticModel model, InvocationExpressionSyntax invocation, IMethodSymbol stashMethod)
Expand Down

0 comments on commit d9ef886

Please sign in to comment.