提交 bff8f821 编写于 作者: C CyrusNajmabadi

Use immutable arrays in more places.

上级 61627a4e
......@@ -56,7 +56,7 @@ internal partial class FindReferencesSearchEngine
_progressTracker = new StreamingProgressTracker(progress.ReportProgressAsync);
}
public async Task<IEnumerable<ReferencedSymbol>> FindReferencesAsync(
public async Task<ImmutableArray<ReferencedSymbol>> FindReferencesAsync(
SymbolAndProjectId symbolAndProjectId)
{
await _progress.OnStartedAsync().ConfigureAwait(false);
......
......@@ -37,9 +37,8 @@ protected AbstractMethodOrPropertyOrEventSymbolReferenceFinder()
{
// We have a normal method. Find any interface methods that it implicitly or
// explicitly implements and cascade down to those.
var interfaceMembersImplementedStream = await SymbolFinder.FindImplementedInterfaceMembersAsync(
var interfaceMembersImplemented = await SymbolFinder.FindImplementedInterfaceMembersAsync(
symbolAndProjectId, solution, projects, cancellationToken).ConfigureAwait(false);
var interfaceMembersImplemented = interfaceMembersImplementedStream.ToImmutableArray();
// 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
......
......@@ -336,7 +336,8 @@ public static Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Solution so
/// <summary>
/// Find the symbols for declarations made in source with the specified name.
/// </summary>
public static Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Solution solution, string name, bool ignoreCase, SymbolFilter filter, CancellationToken cancellationToken = default(CancellationToken))
public static async Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(
Solution solution, string name, bool ignoreCase, SymbolFilter filter, CancellationToken cancellationToken = default(CancellationToken))
{
if (solution == null)
{
......@@ -350,24 +351,25 @@ public static Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Solution so
if (string.IsNullOrWhiteSpace(name))
{
return SpecializedTasks.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
using (Logger.LogBlock(FunctionId.SymbolFinder_Solution_Name_FindSourceDeclarationsAsync, cancellationToken))
{
return FindSourceDeclarationsAsyncImpl(solution, SearchQuery.Create(name, ignoreCase), filter, cancellationToken);
return await FindSourceDeclarationsAsyncImpl(
solution, SearchQuery.Create(name, ignoreCase), filter, cancellationToken).ConfigureAwait(false);
}
}
private static async Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsyncImpl(
private static async Task<ImmutableArray<ISymbol>> FindSourceDeclarationsAsyncImpl(
Solution solution, SearchQuery query, SymbolFilter filter, CancellationToken cancellationToken)
{
if (query.Name != null && string.IsNullOrWhiteSpace(query.Name))
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
var result = new List<ISymbol>();
var result = ArrayBuilder<ISymbol>.GetInstance();
foreach (var projectId in solution.ProjectIds)
{
var project = solution.GetProject(projectId);
......@@ -375,7 +377,7 @@ public static Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Solution so
result.AddRange(symbols);
}
return result;
return result.ToImmutableAndFree();
}
/// <summary>
......@@ -433,13 +435,15 @@ public static Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Solution so
/// <summary>
/// Find the symbols for declarations made in source with a matching name.
/// </summary>
public static Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(
public static async Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(
Solution solution, Func<string, bool> predicate, SymbolFilter filter, CancellationToken cancellationToken = default(CancellationToken))
{
return FindSourceDeclarationsAsync(solution, SearchQuery.CreateCustom(predicate), filter, cancellationToken);
return await FindSourceDeclarationsAsync(
solution, SearchQuery.CreateCustom(predicate), filter, cancellationToken).ConfigureAwait(false);
}
internal static async Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Solution solution, SearchQuery query, SymbolFilter filter, CancellationToken cancellationToken)
internal static async Task<ImmutableArray<ISymbol>> FindSourceDeclarationsAsync(
Solution solution, SearchQuery query, SymbolFilter filter, CancellationToken cancellationToken)
{
if (solution == null)
{
......@@ -448,12 +452,12 @@ internal static async Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Sol
if (query.Name != null && string.IsNullOrWhiteSpace(query.Name))
{
return SpecializedCollections.EmptyEnumerable<ISymbol>();
return ImmutableArray<ISymbol>.Empty;
}
using (Logger.LogBlock(FunctionId.SymbolFinder_Solution_Predicate_FindSourceDeclarationsAsync, cancellationToken))
{
var result = new List<ISymbol>();
var result = ArrayBuilder<ISymbol>.GetInstance();
foreach (var projectId in solution.ProjectIds)
{
var project = solution.GetProject(projectId);
......@@ -461,7 +465,7 @@ internal static async Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Sol
result.AddRange(symbols);
}
return result;
return result.ToImmutableAndFree();
}
}
......
......@@ -78,10 +78,10 @@ public static partial class SymbolFinder
var result = await FindImplementedInterfaceMembersAsync(
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>> FindImplementedInterfaceMembersAsync(
internal static async Task<ImmutableArray<SymbolAndProjectId>> FindImplementedInterfaceMembersAsync(
SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet<Project> projects = null, CancellationToken cancellationToken = default(CancellationToken))
{
// Member can only implement interface members if it is an explicit member, or if it is
......@@ -92,7 +92,7 @@ public static partial class SymbolFinder
var explicitImplementations = symbol.ExplicitInterfaceImplementations();
if (explicitImplementations.Length > 0)
{
return explicitImplementations.Select(symbolAndProjectId.WithSymbol);
return explicitImplementations.SelectAsArray(symbolAndProjectId.WithSymbol);
}
else if (
symbol.DeclaredAccessibility == Accessibility.Public && !symbol.IsStatic &&
......@@ -116,7 +116,7 @@ public static partial class SymbolFinder
containingType, solution, projects, cancellationToken).ConfigureAwait(false);
var allTypes = derivedClasses.Concat(containingType);
List<SymbolAndProjectId> results = null;
var builder = ArrayBuilder<SymbolAndProjectId>.GetInstance();
foreach (var type in allTypes.Convert<INamedTypeSymbol, ITypeSymbol>())
{
......@@ -136,8 +136,7 @@ public static partial class SymbolFinder
if (implementation.Symbol != null &&
SymbolEquivalenceComparer.Instance.Equals(implementation.Symbol.OriginalDefinition, symbol.OriginalDefinition))
{
results = results ?? new List<SymbolAndProjectId>();
results.Add(bestMethod);
builder.Add(bestMethod);
}
}
}
......@@ -145,14 +144,14 @@ public static partial class SymbolFinder
}
}
if (results != null)
{
return results.Distinct(SymbolAndProjectIdComparer.SymbolEquivalenceInstance);
}
var result = builder.Distinct(SymbolAndProjectIdComparer.SymbolEquivalenceInstance)
.ToImmutableArray();
builder.Free();
return result;
}
}
return SpecializedCollections.EmptyEnumerable<SymbolAndProjectId>();
return ImmutableArray<SymbolAndProjectId>.Empty;
}
private static IEnumerable<SymbolAndProjectId> GetMembers(
......
......@@ -90,7 +90,7 @@ public static partial class SymbolFinder
}
}
internal static async Task<IEnumerable<ReferencedSymbol>> FindRenamableReferencesAsync(
internal static async Task<ImmutableArray<ReferencedSymbol>> FindRenamableReferencesAsync(
SymbolAndProjectId symbolAndProjectId,
Solution solution,
CancellationToken cancellationToken)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册