提交 afbb2817 编写于 作者: C CyrusNajmabadi

Use immutable arrays in more places.

上级 5bafb169
......@@ -38,7 +38,7 @@ internal static class DependentTypeFinder
/// <summary>
/// Used for implementing the Inherited-By relation for progression.
/// </summary>
internal static Task<IEnumerable<SymbolAndProjectId<INamedTypeSymbol>>> FindImmediatelyDerivedClassesAsync(
internal static Task<ImmutableArray<SymbolAndProjectId<INamedTypeSymbol>>> FindImmediatelyDerivedClassesAsync(
INamedTypeSymbol type,
Solution solution,
CancellationToken cancellationToken)
......@@ -51,7 +51,7 @@ internal static class DependentTypeFinder
/// <summary>
/// This is an internal implementation of <see cref="SymbolFinder.FindDerivedClassesAsync(SymbolAndProjectId{INamedTypeSymbol}, Solution, IImmutableSet{Project}, CancellationToken)"/>, which is a publically callable method.
/// </summary>
public static Task<IEnumerable<SymbolAndProjectId<INamedTypeSymbol>>> FindTransitivelyDerivedClassesAsync(
public static Task<ImmutableArray<SymbolAndProjectId<INamedTypeSymbol>>> FindTransitivelyDerivedClassesAsync(
INamedTypeSymbol type,
Solution solution,
IImmutableSet<Project> projects,
......@@ -62,7 +62,7 @@ internal static class DependentTypeFinder
transitive: true, cancellationToken: cancellationToken);
}
private static Task<IEnumerable<SymbolAndProjectId<INamedTypeSymbol>>> FindDerivedClassesAsync(
private static Task<ImmutableArray<SymbolAndProjectId<INamedTypeSymbol>>> FindDerivedClassesAsync(
SymbolAndProjectId<INamedTypeSymbol> type,
Solution solution,
IImmutableSet<Project> projects,
......@@ -85,7 +85,7 @@ internal static class DependentTypeFinder
cancellationToken: cancellationToken);
}
return SpecializedTasks.EmptyEnumerable<SymbolAndProjectId<INamedTypeSymbol>>();
return SpecializedTasks.EmptyImmutableArray<SymbolAndProjectId<INamedTypeSymbol>>();
}
/// <summary>
......@@ -109,7 +109,7 @@ internal static class DependentTypeFinder
/// <summary>
/// Used for implementing the Inherited-By relation for progression.
/// </summary>
internal static Task<IEnumerable<SymbolAndProjectId<INamedTypeSymbol>>> FindImmediatelyDerivedAndImplementingTypesAsync(
internal static Task<ImmutableArray<SymbolAndProjectId<INamedTypeSymbol>>> FindImmediatelyDerivedAndImplementingTypesAsync(
INamedTypeSymbol type,
Solution solution,
CancellationToken cancellationToken)
......@@ -119,7 +119,7 @@ internal static class DependentTypeFinder
transitive: false, cancellationToken: cancellationToken);
}
private static Task<IEnumerable<SymbolAndProjectId<INamedTypeSymbol>>> FindDerivedAndImplementingTypesAsync(
private static Task<ImmutableArray<SymbolAndProjectId<INamedTypeSymbol>>> FindDerivedAndImplementingTypesAsync(
SymbolAndProjectId<INamedTypeSymbol> type,
Solution solution,
IImmutableSet<Project> projects,
......@@ -141,10 +141,10 @@ internal static class DependentTypeFinder
cancellationToken: cancellationToken);
}
return SpecializedTasks.EmptyEnumerable<SymbolAndProjectId<INamedTypeSymbol>>();
return SpecializedTasks.EmptyImmutableArray<SymbolAndProjectId<INamedTypeSymbol>>();
}
private static async Task<IEnumerable<SymbolAndProjectId<INamedTypeSymbol>>> FindTypesAsync(
private static async Task<ImmutableArray<SymbolAndProjectId<INamedTypeSymbol>>> FindTypesAsync(
SymbolAndProjectId<INamedTypeSymbol> type,
Solution solution,
IImmutableSet<Project> projects,
......@@ -214,7 +214,7 @@ internal static class DependentTypeFinder
transitive, cancellationToken).ConfigureAwait(false);
}
return result;
return result.ToImmutableArray();
}
private static async Task FindTypesInProjectAsync(
......
......@@ -44,9 +44,8 @@ protected AbstractMethodOrPropertyOrEventSymbolReferenceFinder()
// Finally, methods can cascade through virtual/override inheritance. NOTE(cyrusn):
// We only need to go up or down one level. Then, when we're finding references on
// those members, we'll end up traversing the entire hierarchy.
var overridesStream = await SymbolFinder.FindOverridesAsync(
var overrides = await SymbolFinder.FindOverridesAsync(
symbolAndProjectId, solution, projects, cancellationToken).ConfigureAwait(false);
var overrides = overridesStream.ToImmutableArray();
var overriddenMember = symbolAndProjectId.WithSymbol(symbol.OverriddenMember());
if (overriddenMember.Symbol == null)
......
......@@ -26,10 +26,10 @@ public static partial class SymbolFinder
SymbolAndProjectId.Create(symbol, projectId: null),
solution, projects, cancellationToken).ConfigureAwait(false);
return result.Select(s => s.Symbol).ToList();
return result.SelectAsArray(s => s.Symbol);
}
internal static async Task<IEnumerable<SymbolAndProjectId>> FindOverridesAsync(
internal static async Task<ImmutableArray<SymbolAndProjectId>> FindOverridesAsync(
SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet<Project> projects = null, CancellationToken cancellationToken = default(CancellationToken))
{
// Method can only have overrides if its a virtual, abstract or override and is not
......@@ -45,7 +45,7 @@ public static partial class SymbolFinder
symbolAndProjectId.WithSymbol(containingType),
solution, projects, cancellationToken).ConfigureAwait(false);
List<SymbolAndProjectId> results = null;
var results = ArrayBuilder<SymbolAndProjectId>.GetInstance();
foreach (var type in derivedTypes)
{
foreach (var m in GetMembers(type, symbol.Name))
......@@ -58,19 +58,15 @@ public static partial class SymbolFinder
member.OverriddenMember() != null &&
OriginalSymbolsMatch(member.OverriddenMember().OriginalDefinition, symbol.OriginalDefinition, solution, cancellationToken))
{
results = results ?? new List<SymbolAndProjectId>();
results.Add(bestMember);
}
}
}
if (results != null)
{
return results;
}
return results.ToImmutableAndFree();
}
return SpecializedCollections.EmptyEnumerable<SymbolAndProjectId>();
return ImmutableArray<SymbolAndProjectId>.Empty;
}
/// <summary>
......@@ -186,10 +182,10 @@ public static partial class SymbolFinder
var result = await FindDerivedClassesAsync(
SymbolAndProjectId.Create(type, projectId: null),
solution, projects, cancellationToken).ConfigureAwait(false);
return result.Select(s => s.Symbol).ToList();
return result.SelectAsArray(s => s.Symbol);
}
internal static Task<IEnumerable<SymbolAndProjectId<INamedTypeSymbol>>> FindDerivedClassesAsync(
internal static Task<ImmutableArray<SymbolAndProjectId<INamedTypeSymbol>>> FindDerivedClassesAsync(
SymbolAndProjectId<INamedTypeSymbol> typeAndProjectId, Solution solution, IImmutableSet<Project> projects = null, CancellationToken cancellationToken = default(CancellationToken))
{
var type = typeAndProjectId.Symbol;
......@@ -215,7 +211,7 @@ public static partial class SymbolFinder
var result = await FindImplementationsAsync(
SymbolAndProjectId.Create(symbol, projectId: null),
solution, projects, cancellationToken).ConfigureAwait(false);
return result.Select(s => s.Symbol).ToList();
return result.SelectAsArray(s => s.Symbol);
}
internal static async Task<ImmutableArray<SymbolAndProjectId>> FindImplementationsAsync(
......@@ -299,7 +295,7 @@ public static async Task<IEnumerable<SymbolCallerInfo>> FindCallersAsync(ISymbol
var directReferences = callReferences.Where(
r => SymbolEquivalenceComparer.Instance.Equals(symbol, r.Definition)).FirstOrDefault();
var indirectReferences = callReferences.Where(r => r != directReferences).ToList();
var indirectReferences = callReferences.WhereAsArray(r => r != directReferences);
List<SymbolCallerInfo> results = null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册