Skip to content

Commit bf03ff2

Browse files
committed
! Optimized FindDerivedInterface command slightly
1 parent 5d6041f commit bf03ff2

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

Codist/Controls/SymbolCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal static async Task FindDerivedClassesAsync(this SemanticContext context,
4848
}
4949

5050
internal static async Task FindSubInterfacesAsync(this SemanticContext context, ISymbol symbol) {
51-
var interfaces = (await (symbol as INamedTypeSymbol).FindDerivedInterfacesAsync(context.Document.Project, default).ConfigureAwait(false)).ToList();
51+
var interfaces = await (symbol as INamedTypeSymbol).FindDerivedInterfacesAsync(context.Document.Project, default).ConfigureAwait(false);
5252
await TH.JoinableTaskFactory.SwitchToMainThreadAsync(default);
5353
ShowSymbolMenuForResult(symbol, context, interfaces, R.T_DerivedInterfaces, false);
5454
}

Codist/Helpers/CodeAnalysisHelper.SymbolFinder.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,15 @@ public static async Task<List<ISymbol>> FindSymbolInstanceProducerAsync(this ITy
150150
return members;
151151
}
152152

153-
public static async Task<List<INamedTypeSymbol>> FindDerivedInterfacesAsync(this ITypeSymbol type, Project project, CancellationToken cancellationToken = default) {
153+
/// <summary>Returns interfaces derived from the given interface <paramref name="type"/> in specific <paramref name="project"/>.</summary>
154+
public static async Task<List<INamedTypeSymbol>> FindDerivedInterfacesAsync(this INamedTypeSymbol type, Project project, CancellationToken cancellationToken = default) {
154155
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
155-
var r = new List<INamedTypeSymbol>();
156+
var r = new List<INamedTypeSymbol>(7);
156157
foreach (var item in compilation.GlobalNamespace.GetAllTypes(cancellationToken)) {
157-
if (item.TypeKind != TypeKind.Interface || item == type) {
158-
continue;
159-
}
160-
var inf = item as INamedTypeSymbol;
161-
if (inf.AllInterfaces.Contains(type)) {
162-
r.Add(inf);
158+
if (item.TypeKind == TypeKind.Interface
159+
&& item != type
160+
&& item.AllInterfaces.Contains(type)) {
161+
r.Add(item);
163162
}
164163
}
165164
return r;

0 commit comments

Comments
 (0)