Skip to content

Commit

Permalink
Merge pull request #51506 from sharwell/avoid-captures
Browse files Browse the repository at this point in the history
Avoid captures for AnyAsync
  • Loading branch information
sharwell authored Feb 26, 2021
2 parents 11660ce + a78f429 commit e6aabad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,22 @@ public static async Task<bool> AnyAsync<T>(this ImmutableArray<T> array, Func<T,
return false;
}

public static async Task<bool> AnyAsync<T, TArg>(this ImmutableArray<T> array, Func<T, TArg, Task<bool>> predicateAsync, TArg arg)
{
int n = array.Length;
for (int i = 0; i < n; i++)
{
var a = array[i];

if (await predicateAsync(a, arg).ConfigureAwait(false))
{
return true;
}
}

return false;
}

public static async ValueTask<T?> FirstOrDefaultAsync<T>(this ImmutableArray<T> array, Func<T, Task<bool>> predicateAsync)
{
int n = array.Length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ protected static async Task<ImmutableArray<SyntaxToken>> GetIdentifierOrGlobalNa
{
return (matched: true, CandidateReason.None);
}
else if (await symbolInfoToMatch.CandidateSymbols.AnyAsync(s => SymbolFinder.OriginalSymbolsMatchAsync(solution, searchSymbol, s, cancellationToken)).ConfigureAwait(false))
else if (await symbolInfoToMatch.CandidateSymbols.AnyAsync(static (s, arg) => SymbolFinder.OriginalSymbolsMatchAsync(arg.solution, arg.searchSymbol, s, arg.cancellationToken), (solution, searchSymbol, cancellationToken)).ConfigureAwait(false))
{
return (matched: true, symbolInfoToMatch.CandidateReason);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ internal static async Task<bool> OriginalSymbolsMatchAsync(
var namespace2Count = namespace2.ConstituentNamespaces.Length;
if (namespace1Count != namespace2Count)
{
if ((namespace1Count > 1 && await namespace1.ConstituentNamespaces.AnyAsync(n => NamespaceSymbolsMatchAsync(solution, n, namespace2, cancellationToken)).ConfigureAwait(false)) ||
(namespace2Count > 1 && await namespace2.ConstituentNamespaces.AnyAsync(n2 => NamespaceSymbolsMatchAsync(solution, namespace1, n2, cancellationToken)).ConfigureAwait(false)))
if ((namespace1Count > 1 && await namespace1.ConstituentNamespaces.AnyAsync(static (n, arg) => NamespaceSymbolsMatchAsync(arg.solution, n, arg.namespace2, arg.cancellationToken), (solution, namespace2, cancellationToken)).ConfigureAwait(false)) ||
(namespace2Count > 1 && await namespace2.ConstituentNamespaces.AnyAsync(static (n2, arg) => NamespaceSymbolsMatchAsync(arg.solution, arg.namespace1, n2, arg.cancellationToken), (solution, namespace1, cancellationToken)).ConfigureAwait(false)))
{
return true;
}
Expand Down

0 comments on commit e6aabad

Please sign in to comment.