未验证 提交 5523eec3 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #30671 from iharwell/master

Rearranged query to avoid unnecessary allocations
......@@ -159,15 +159,21 @@ private static AnalyzerLoadFailureEventArgs CreateAnalyzerFailedArgs(Exception e
/// </summary>
/// <exception cref="BadImageFormatException">The PE image format is invalid.</exception>
/// <exception cref="IOException">IO error reading the metadata.</exception>
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/30449")]
private static ImmutableDictionary<string, ImmutableHashSet<string>> GetAnalyzerTypeNameMap(string fullPath, AttributePredicate attributePredicate)
{
using (var assembly = AssemblyMetadata.CreateFromFile(fullPath))
{
// This is longer than strictly necessary to avoid thrashing the GC with string allocations
// in the call to GetFullyQualifiedTypeNames. Specifically, this checks for the presence of
// supported languages prior to creating the type names.
var typeNameMap = from module in assembly.GetModules()
from typeDefHandle in module.MetadataReader.TypeDefinitions
let typeDef = module.MetadataReader.GetTypeDefinition(typeDefHandle)
let supportedLanguages = GetSupportedLanguages(typeDef, module.Module, attributePredicate)
where supportedLanguages.Any()
let typeName = GetFullyQualifiedTypeName(typeDef, module.Module)
from supportedLanguage in GetSupportedLanguages(typeDef, module.Module, attributePredicate)
from supportedLanguage in supportedLanguages
group typeName by supportedLanguage;
return typeNameMap.ToImmutableDictionary(g => g.Key, g => g.ToImmutableHashSet());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册