Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetOrCreateTypeByMetadataName is called on every attribute syntax callback #5123

Closed
Youssef1313 opened this issue May 22, 2021 · 1 comment · Fixed by #5124
Closed

GetOrCreateTypeByMetadataName is called on every attribute syntax callback #5123

Youssef1313 opened this issue May 22, 2021 · 1 comment · Fixed by #5124
Labels
Enhancement help wanted The issue is up-for-grabs, and can be claimed by commenting

Comments

@Youssef1313
Copy link
Member

context.RegisterSyntaxNodeAction(nc =>
{
if (!CheckAttribute(nc.Node))
{
return;
}
if (!CheckResxGeneratedFile(nc.SemanticModel, nc.Node, ((AttributeSyntax)nc.Node).ArgumentList.Arguments[0].Expression, nc.CancellationToken))
{
return;
}
onResourceFound();
}, SyntaxKind.Attribute);
}

protected static bool CheckResxGeneratedFile(SemanticModel model, SyntaxNode attribute, SyntaxNode argument, CancellationToken cancellationToken)
{
if (!CheckDesignerFile(model.SyntaxTree))
{
return false;
}
INamedTypeSymbol? generatedCode = model.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCodeDomCompilerGeneratedCodeAttribute);

Should see if this impacts performance and move the call to GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemCodeDomCompilerGeneratedCodeAttribute); to the compilation start action

@jmarolf jmarolf added Enhancement help wanted The issue is up-for-grabs, and can be claimed by commenting labels Jun 10, 2021
@Evangelink
Copy link
Member

Impact should be relatively moderated (method call + dict lookup) but the PR is still totally worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement help wanted The issue is up-for-grabs, and can be claimed by commenting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants