-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Implemented NextAre #1001
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
Implemented NextAre #1001
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -389,6 +389,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax | |
| #End Region | ||
|
|
||
| #Region "Buffer helpers" | ||
|
|
||
| Private Function NextAre(offset As Integer, chars As String) As Boolean | ||
| Debug.Assert(Not String.IsNullOrEmpty(chars)) | ||
| Dim n = chars.Length | ||
| If Not CanGetCharAtOffset(offset + n) Then Return False | ||
| For i = 0 To n - 1 | ||
| If chars(i) <> PeekAheadChar(offset + i) Then Return False | ||
| Next | ||
| Return True | ||
| End Function | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please separate method declarations with an empty line.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So noted and added in 6396a55
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please rewrite this method for clarity as suggested by @pharring In the issue thread? |
||
|
|
||
| Private Function CanGetChar() As Boolean | ||
| Return _lineBufferOffset < _bufferLen | ||
| End Function | ||
|
|
@@ -1109,9 +1120,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax | |
| Return ScanStringLiteral(precedingTrivia) | ||
|
|
||
| Case "A"c | ||
| If CanGetCharAtOffset(2) AndAlso | ||
| PeekAheadChar(1) = "s"c AndAlso | ||
| PeekAheadChar(2) = " "c Then | ||
| If NextAre(1, "s ") Then | ||
|
|
||
| ' TODO: do we allow widechars in keywords? | ||
| Dim spelling = "As" | ||
|
|
@@ -1122,10 +1131,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax | |
| End If | ||
|
|
||
| Case "E"c | ||
| If CanGetCharAtOffset(3) AndAlso | ||
| PeekAheadChar(1) = "n"c AndAlso | ||
| PeekAheadChar(2) = "d"c AndAlso | ||
| PeekAheadChar(3) = " "c Then | ||
| If NextAre(1, "nd ") Then | ||
|
|
||
| ' TODO: do we allow widechars in keywords? | ||
| Dim spelling = "End" | ||
|
|
@@ -1136,9 +1142,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax | |
| End If | ||
|
|
||
| Case "I"c | ||
| If CanGetCharAtOffset(2) AndAlso | ||
| PeekAheadChar(1) = "f"c AndAlso | ||
| PeekAheadChar(2) = " "c Then | ||
| If NextAre(1, "f ") Then | ||
|
|
||
| ' TODO: do we allow widechars in keywords? | ||
| Dim spelling = "If" | ||
|
|
@@ -1148,9 +1152,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax | |
| Return ScanIdentifierOrKeyword(precedingTrivia) | ||
| End If | ||
|
|
||
| Case "a"c, "b"c, "c"c, "d"c, "e"c, "f"c, "g"c, "h"c, "i"c, "j"c, "k"c, "l"c, | ||
| "m"c, "n"c, "o"c, "p"c, "q"c, "r"c, "s"c, "t"c, "u"c, "v"c, "w"c, "x"c, | ||
| "y"c, "z"c | ||
| Case "a"c, "b"c, "c"c, "d"c, "e"c, "f"c, "g"c, "h"c, "i"c, "j"c, "k"c, "l"c, "m"c, | ||
| "n"c, "o"c, "p"c, "q"c, "r"c, "s"c, "t"c, "u"c, "v"c, "w"c, "x"c, "y"c, "z"c | ||
| Return ScanIdentifierOrKeyword(precedingTrivia) | ||
|
|
||
| Case "B"c, "C"c, "D"c, "F"c, "G"c, "H"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, | ||
|
|
@@ -1347,43 +1350,32 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax | |
| Return ScanStringLiteral(precedingTrivia) | ||
|
|
||
| Case "A"c | ||
| If CanGetCharAtOffset(2) AndAlso | ||
| PeekAheadChar(1) = "s"c AndAlso | ||
| PeekAheadChar(2) = " "c Then | ||
|
|
||
| If NextAre(1, "s ") Then | ||
| Dim spelling = GetText(2) | ||
| Return MakeKeyword(SyntaxKind.AsKeyword, spelling, precedingTrivia) | ||
| Else | ||
| Return ScanIdentifierOrKeyword(precedingTrivia) | ||
| End If | ||
|
|
||
| Case "E"c | ||
| If CanGetCharAtOffset(3) AndAlso | ||
| PeekAheadChar(1) = "n"c AndAlso | ||
| PeekAheadChar(2) = "d"c AndAlso | ||
| PeekAheadChar(3) = " "c Then | ||
|
|
||
| If NextAre(1, "nd ") Then | ||
| Dim spelling = GetText(3) | ||
| Return MakeKeyword(SyntaxKind.EndKeyword, spelling, precedingTrivia) | ||
| Else | ||
| Return ScanIdentifierOrKeyword(precedingTrivia) | ||
| End If | ||
|
|
||
| Case "I"c | ||
| If CanGetCharAtOffset(2) AndAlso | ||
| PeekAheadChar(1) = "f"c AndAlso | ||
| PeekAheadChar(2) = " "c Then | ||
|
|
||
| If NextAre(1, "f ") Then | ||
| ' TODO: do we allow widechars in keywords? | ||
| Dim spelling = GetText(2) | ||
| Return MakeKeyword(SyntaxKind.IfKeyword, spelling, precedingTrivia) | ||
| Else | ||
| Return ScanIdentifierOrKeyword(precedingTrivia) | ||
| End If | ||
|
|
||
| Case "a"c, "b"c, "c"c, "d"c, "e"c, "f"c, "g"c, "h"c, "i"c, "j"c, "k"c, "l"c, | ||
| "m"c, "n"c, "o"c, "p"c, "q"c, "r"c, "s"c, "t"c, "u"c, "v"c, "w"c, "x"c, | ||
| "y"c, "z"c | ||
| Case "a"c, "b"c, "c"c, "d"c, "e"c, "f"c, "g"c, "h"c, "i"c, "j"c, "k"c, "l"c, "m"c, | ||
| "n"c, "o"c, "p"c, "q"c, "r"c, "s"c, "t"c, "u"c, "v"c, "w"c, "x"c, "y"c, "z"c | ||
| Return ScanIdentifierOrKeyword(precedingTrivia) | ||
|
|
||
| Case "B"c, "C"c, "D"c, "F"c, "G"c, "H"c, "J"c, "K"c, "L"c, "M"c, "N"c, "O"c, "P"c, "Q"c, | ||
|
|
@@ -1496,13 +1488,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax | |
| Return XmlMakeBeginCommentToken(precedingTrivia, scanTrailingTrivia) | ||
| End If | ||
| Case "["c | ||
| If CanGetCharAtOffset(length + 8) AndAlso | ||
| PeekAheadChar(length + 2) = "C"c AndAlso | ||
| PeekAheadChar(length + 3) = "D"c AndAlso | ||
| PeekAheadChar(length + 4) = "A"c AndAlso | ||
| PeekAheadChar(length + 5) = "T"c AndAlso | ||
| PeekAheadChar(length + 6) = "A"c AndAlso | ||
| PeekAheadChar(length + 7) = "["c Then | ||
|
|
||
| If NextAre(length + 2, "CDATA[") Then | ||
|
|
||
| Return XmlMakeBeginCDataToken(precedingTrivia, scanTrailingTrivia) | ||
| End If | ||
|
|
||
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.
Have you measured performance effects of this change? Is this method being inlined by JIT?
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.
The build I have is
Debugso it isn't optimised. It the IL it is a method call.Since its been extracted out we can "play" with different internal implementations.