-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change IReferenceFinder.DetermineDocumentsToSearchAsync to not return an ImmutableArray #73093
Change IReferenceFinder.DetermineDocumentsToSearchAsync to not return an ImmutableArray #73093
Conversation
… an ImmutableArray Rather, this method now encourages items that wish to be part of the result to invoke a callback with that result. This prevents quite a few intermediary array allocations during find references invocations.
@@ -190,6 +190,8 @@ private async Task ProcessProjectAsync(Project project, ImmutableArray<ISymbol> | |||
using var _2 = PooledDictionary<Document, MetadataUnifyingSymbolHashSet>.GetInstance(out var documentToSymbols); | |||
try | |||
{ | |||
using var _3 = ArrayBuilder<Document>.GetInstance(out var documents); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe doc semantics. call it documentsBuffer indicating it will be reset/cleared on iterations?
@@ -43,20 +46,18 @@ protected override bool CanFind(IMethodSymbol symbol) | |||
|
|||
var underlyingNamedType = GetUnderlyingNamedType(symbol.ReturnType); | |||
Contract.ThrowIfNull(underlyingNamedType); | |||
var documentsWithName = await FindDocumentsAsync(project, documents, cancellationToken, underlyingNamedType.Name).ConfigureAwait(false); | |||
var documentsWithType = await FindDocumentsAsync(project, documents, underlyingNamedType.SpecialType.ToPredefinedType(), cancellationToken).ConfigureAwait(false); | |||
|
|||
using var _ = ArrayBuilder<Document>.GetInstance(out var result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit (and you're preserving logic, so up to you), but chaneg this to a pooled hashset. it was an array before to keep all the sigs the same. but now that this is callbac style, this can change.
…shset to allow unique-doc semantics
using var _ = ArrayBuilder<Document>.GetInstance(out var result); | ||
using var _ = PooledHashSet<Document>.GetInstance(out var result); | ||
await FindDocumentsAsync(project, documents, static (doc, result) => result.Add(doc), result, cancellationToken, underlyingNamedType.Name).ConfigureAwait(false); | ||
await FindDocumentsAsync(project, documents, underlyingNamedType.SpecialType.ToPredefinedType(), static (doc, result) => result.Add(doc), result, cancellationToken).ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit. ont thing i've been thinking about is the repetition of things like static (doc, result) => result.Add(doc)
. Consider a protected static in the topmost type like Action<...> StandardAddCallback
and reference those here. (may not work due to genercs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went ahead and made that change (I like the idea, but these were the only ones I could find).
...Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/OrdinaryMethodReferenceFinder.cs
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
…ations> created during find references invocations. This is very similar to this PR (dotnet#73093) that did the same thing for ImmutableArray<Document> in this context.
Rather, this method now utilizes a callback to be invoked with results. This prevents quite a few intermediary array allocations during find references invocations.