Skip to content

Commit 63e8844

Browse files
authored
Merge pull request #19863 from Therzok/patch-2
[Perf] Optimize IsOrContainsAccessibleAttribute
2 parents e20ca27 + 8044437 commit 63e8844

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,16 @@ public static bool IsOrContainsAccessibleAttribute(this ISymbol symbol, ISymbol
565565
return true;
566566
}
567567

568-
return namespaceOrType.GetMembers().Any(nt => nt.IsOrContainsAccessibleAttribute(withinType, withinAssembly));
568+
// PERF: Avoid allocating a lambda capture as this method is recursive
569+
foreach (var namedType in namespaceOrType.GetTypeMembers())
570+
{
571+
if (namedType.IsOrContainsAccessibleAttribute(withinType, withinAssembly))
572+
{
573+
return true;
574+
}
575+
}
576+
577+
return false;
569578
}
570579

571580
public static IEnumerable<IPropertySymbol> GetValidAnonymousTypeProperties(this ISymbol symbol)

0 commit comments

Comments
 (0)