-
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
Add struct base enumerator for interval trees. #73877
Add struct base enumerator for interval trees. #73877
Conversation
@@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.Shared.Collections; | |||
|
|||
internal partial class MutableIntervalTree<T> | |||
{ | |||
protected sealed class Node | |||
internal sealed class Node |
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.
needed as it's part of the signature of the public GetEnumerator now (can't have generic struct enumerators without leaking details like this).
where TIntervalTree : IIntervalTree<T> | ||
where TIntervalTreeWitness : struct, IIntervalTreeWitness<T, TIntervalTree, TNode> | ||
{ | ||
private static readonly ObjectPool<Stack<TNode>> s_nodeStackPool = new(() => new(), 128, trimOnFree: false); | ||
|
||
public static IEnumerator<T> GetEnumerator(TIntervalTree tree) |
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.
so it is nice that this becomes a struct-enumerator and has no more code for itself anymore.
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Collections/IntervalTreeHelpers.cs
Outdated
Show resolved
Hide resolved
…ections/IntervalTreeHelpers.cs
} | ||
|
||
public readonly void Dispose() | ||
=> _pooledStack.Dispose(); |
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.
this is fine on an unintialized _pooledStack value. Dispose for it checks if it actually has an object from the pool, and no-ops if not.
@@ -171,12 +115,15 @@ public static bool Any<TIntrospector>(TIntervalTree tree, int start, int length, | |||
{ | |||
var witness = default(TIntervalTreeWitness); | |||
|
|||
if (start == int.MinValue && end == int.MaxValue) |
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.
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 bug. But it allows GetEnumerator to work (it wants all nodes and doesn't need/want to pass in an introspector. (It can't either since the callers don't have one).
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; i doc'ed this on Enumerator side so it can be clear that it is intentionally passing in the full span, but not bothering with any sort of introspector (since it doesn't have one).
...ces/SharedUtilitiesAndExtensions/Compiler/Core/Collections/IntervalTreeHelpers.Enumerator.cs
Outdated
Show resolved
Hide resolved
...SharedUtilitiesAndExtensions/Compiler/Core/Collections/IntervalTreeHelpers.NodeEnumerator.cs
Outdated
Show resolved
Hide resolved
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 description provided.