Skip to content

Commit

Permalink
Rewrite AnalyzeFileReference.GetSupportedLanguages without LINQ (#49337)
Browse files Browse the repository at this point in the history
I did an allocation profile of csc.dll for building a simple "hello world" with the configuration `dotnet build` employs on a simple `dotnet new console` app.  There are ~194K allocations / ~19MB.  And ~30K / ~1MB of those are occurring unnecessarily because of use of LINQ in one function.  This just rewrites that function to not use LINQ.
  • Loading branch information
stephentoub authored Nov 13, 2020
1 parent de99c46 commit 8cbae31
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,20 @@ from supportedLanguage in supportedLanguages

private static IEnumerable<string> GetSupportedLanguages(TypeDefinition typeDef, PEModule peModule, Type attributeType, AttributeLanguagesFunc languagesFunc)
{
var attributeLanguagesList = from customAttrHandle in typeDef.GetCustomAttributes()
where peModule.IsTargetAttribute(customAttrHandle, attributeType.Namespace!, attributeType.Name, ctor: out _)
let attributeSupportedLanguages = languagesFunc(peModule, customAttrHandle)
where attributeSupportedLanguages != null
select attributeSupportedLanguages;
return attributeLanguagesList.SelectMany(x => x);
foreach (CustomAttributeHandle customAttrHandle in typeDef.GetCustomAttributes())
{
if (peModule.IsTargetAttribute(customAttrHandle, attributeType.Namespace!, attributeType.Name, ctor: out _))
{
IEnumerable<string>? attributeSupportedLanguages = languagesFunc(peModule, customAttrHandle);
if (attributeSupportedLanguages != null)
{
foreach (string item in attributeSupportedLanguages)
{
yield return item;
}
}
}
}
}

private static IEnumerable<string> GetDiagnosticsAnalyzerSupportedLanguages(PEModule peModule, CustomAttributeHandle customAttrHandle)
Expand Down

0 comments on commit 8cbae31

Please sign in to comment.