diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Collections/IntervalTree`1.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Collections/IntervalTree`1.cs index bfb328bb10067a9778f4477a4af28de1826b4ee3..1b8c44a7742012f28fb0a367cbe1527f5ff2f73b 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Collections/IntervalTree`1.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Collections/IntervalTree`1.cs @@ -140,9 +140,8 @@ public bool HasIntervalThatContains(int start, int length, in TIn private bool Any(int start, int length, TestInterval testInterval, in TIntrospector introspector) where TIntrospector : struct, IIntervalIntrospector { - using var _ = ArrayBuilder.GetInstance(out var builder); - FillWithIntervalsThatMatch(start, length, testInterval, builder, in introspector, stopAfterFirst: true); - return builder.Count > 0; + var matches = FillWithIntervalsThatMatch(start, length, testInterval, builder: null, in introspector, stopAfterFirst: true); + return matches > 0; } private ImmutableArray GetIntervalsThatMatch( @@ -154,33 +153,38 @@ private bool Any(int start, int length, TestInterval( + /// The number of matching intervals found by the method. + private int FillWithIntervalsThatMatch( int start, int length, TestInterval testInterval, - ArrayBuilder builder, in TIntrospector introspector, + ArrayBuilder? builder, in TIntrospector introspector, bool stopAfterFirst) where TIntrospector : struct, IIntervalIntrospector { if (root == null) { - return; + return 0; } var candidates = s_stackPool.Allocate(); - FillWithIntervalsThatMatch( + var matches = FillWithIntervalsThatMatch( start, length, testInterval, builder, in introspector, stopAfterFirst, candidates); s_stackPool.ClearAndFree(candidates); + + return matches; } - private void FillWithIntervalsThatMatch( + /// The number of matching intervals found by the method. + private int FillWithIntervalsThatMatch( int start, int length, TestInterval testInterval, - ArrayBuilder builder, in TIntrospector introspector, + ArrayBuilder? builder, in TIntrospector introspector, bool stopAfterFirst, Stack<(Node? node, bool firstTime)> candidates) where TIntrospector : struct, IIntervalIntrospector { + var matches = 0; var end = start + length; candidates.Push((root, firstTime: true)); @@ -199,11 +203,12 @@ private bool Any(int start, int length, TestInterval(int start, int length, TestInterval this.root == null;