Skip to content
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

Avoid unnecessary tree walk when hitting non-relevant directives #73720

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,21 @@ internal abstract class AbstractDirectiveTriviaBraceMatcher<TDirectiveTriviaSynt
}

TDirectiveTriviaSyntax? matchingDirective = null;
if (IsConditionalDirective(directive))
if (directive
is TIfDirectiveTriviaSyntax
or TElseIfDirectiveTriviaSyntax
or TElseDirectiveTriviaSyntax
or TEndIfDirectiveTriviaSyntax)
{
// #if/#elif/#else/#endif directive cases.
var matchingDirectives = GetMatchingConditionalDirectives(directive, cancellationToken);
if (matchingDirectives.Length > 0)
matchingDirective = matchingDirectives[(matchingDirectives.IndexOf(directive) + 1) % matchingDirectives.Length];
}
else
else if (directive
is TRegionDirectiveTriviaSyntax
or TEndRegionDirectiveTriviaSyntax)
{
// #region/#endregion or other directive cases.
matchingDirective = GetMatchingDirective(directive, cancellationToken);
}

Expand All @@ -60,10 +65,4 @@ internal abstract class AbstractDirectiveTriviaBraceMatcher<TDirectiveTriviaSynt
LeftSpan: GetSpanForTagging(directive),
RightSpan: GetSpanForTagging(matchingDirective));
}

private static bool IsConditionalDirective(TDirectiveTriviaSyntax directive)
=> directive is TIfDirectiveTriviaSyntax or
TElseIfDirectiveTriviaSyntax or
TElseDirectiveTriviaSyntax or
TEndIfDirectiveTriviaSyntax;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Imports Microsoft.CodeAnalysis.VisualBasic.LanguageService
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax

Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions

Friend Module DirectiveSyntaxExtensions
Private ReadOnly s_rootToDirectiveInfo As New ConditionalWeakTable(Of SyntaxNode, DirectiveInfo(Of DirectiveTriviaSyntax))()

Expand Down
Loading