Skip to content

Commit c195a1f

Browse files
authored
For IsAtDotDotToken, ensure the current token is a DotToken before parsing the next token to see if it's also a DotToken. (#78338)
I see LanguageParser.IsAtDotToken accounting for about 1 second of CPU time (0.5%) in the C# editing speedometer test. Local testing indicates about 85% of calls into this method will be filtered by this check. Test insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/631973 See PR for details on the perf characteristics with and without the change.
1 parent 73f70f4 commit c195a1f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Compilers/CSharp/Portable/Parser/LanguageParser.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11477,7 +11477,13 @@ private AssignmentExpressionSyntax ParseAssignmentExpression(SyntaxKind operator
1147711477

1147811478
/// <summary>Check if we're currently at a .. sequence that can then be parsed out as a <see cref="SyntaxKind.DotDotToken"/>.</summary>
1147911479
public bool IsAtDotDotToken()
11480-
=> IsAtDotDotToken(this.CurrentToken, this.PeekToken(1));
11480+
{
11481+
if (this.CurrentToken.Kind != SyntaxKind.DotToken)
11482+
return false;
11483+
11484+
var nextToken = this.PeekToken(1);
11485+
return nextToken.Kind == SyntaxKind.DotToken && NoTriviaBetween(this.CurrentToken, nextToken);
11486+
}
1148111487

1148211488
public static bool IsAtDotDotToken(SyntaxToken token1, SyntaxToken token2)
1148311489
=> token1.Kind == SyntaxKind.DotToken &&

0 commit comments

Comments
 (0)