-
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
Use a simpler pattern when working with stacks #73057
Conversation
stack.Push(node); | ||
try |
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.
view with whitespace off.
var workQueue = new Stack<ISymbol>(); | ||
workQueue.Push(_allSymbols); | ||
using var _ = ArrayBuilder<ISymbol>.GetInstance(out var workQueue); | ||
workQueue.AddRange(_allSymbols); |
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.
note: AddRange is fine here as _allSymbols is a set, so there's no concept of any sort of order to preserve when pushing onto the stack. Other AddRange calls in this PR work similarly.
if (current is INamespaceSymbol childNamespace) | ||
{ | ||
stack.Push(childNamespace.GetMembers().AsEnumerable()); | ||
stack.AddRange(childNamespace.GetMembers().AsEnumerable()); |
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.
no order of children. AddRange is fine.
|
||
var matches = FillWithIntervalsThatMatch( | ||
start, length, testInterval, | ||
ref builder, in introspector, | ||
stopAfterFirst, candidates); | ||
|
||
s_stackPool.ClearAndFree(candidates); |
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.
already done by the Releaser that a stack-pool uses.
@@ -124,16 +124,15 @@ private static IEnumerable<INamedTypeSymbol> GetTypesInFile(SemanticModel semant | |||
using (Logger.LogBlock(FunctionId.NavigationBar_ItemService_GetTypesInFile_CSharp, cancellationToken)) | |||
{ | |||
var types = new HashSet<INamedTypeSymbol>(); | |||
var nodesToVisit = new Stack<SyntaxNode>(); | |||
using var _ = ArrayBuilder<SyntaxNode>.GetInstance(out var nodesToVisit); |
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.
curious - why are we changing only some usages of Stack
to ArrayBuilder
? Is it instances where we're not using a pooled Stack
?
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.
- Correct. If they had their own pool, I'm trusting them for now
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.
Code not using a pool should, in general, not switch to using pools unless there is a measured problem. Each such change gives up a bit of memory safety and a bit of performance for no known (previously measured) gain.
No description provided.