-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Introduce more efficient internal representation of a sequence VirtualChars #33834
Merged
Merged
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
216b330
Virtual char sequence abstraction
CyrusNajmabadi 0924768
compiling
CyrusNajmabadi f6e246d
Fixes
CyrusNajmabadi 27f7fd5
tests
CyrusNajmabadi c331f91
cleanup
CyrusNajmabadi 788f5e5
optimize
CyrusNajmabadi e0eacd8
Improve docs
CyrusNajmabadi eca2b35
Simplify
CyrusNajmabadi 856a92f
Delete
CyrusNajmabadi f6b5b6d
Simplify
CyrusNajmabadi acd1ed5
Less allocations
CyrusNajmabadi ac824eb
Simplify
CyrusNajmabadi be6df98
Simplyf
CyrusNajmabadi 8c4efaa
REstore
CyrusNajmabadi aed2914
REstore
CyrusNajmabadi 3adac8f
REstore
CyrusNajmabadi a7e29fa
restore
CyrusNajmabadi 41e7025
restore
CyrusNajmabadi 4bdeaec
restore
CyrusNajmabadi 85a9027
restore
CyrusNajmabadi 5be36ea
restore
CyrusNajmabadi 93e9edf
restore
CyrusNajmabadi fa03f71
restore
CyrusNajmabadi ca7b86c
restore
CyrusNajmabadi 77fca69
Cleanup
CyrusNajmabadi 10cecca
Make into local functions
CyrusNajmabadi d6402b2
Update VirtualCharSequence.cs
CyrusNajmabadi 8bfd5c5
Simplify
CyrusNajmabadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
|
||
namespace Microsoft.CodeAnalysis.EmbeddedLanguages.RegularExpressions | ||
{ | ||
using static EmbeddedSyntaxHelpers; | ||
using static RegexHelpers; | ||
|
||
using RegexToken = EmbeddedSyntaxToken<RegexKind>; | ||
|
@@ -37,42 +36,34 @@ namespace Microsoft.CodeAnalysis.EmbeddedLanguages.RegularExpressions | |
/// </summary> | ||
internal struct RegexLexer | ||
{ | ||
public readonly ImmutableArray<VirtualChar> Text; | ||
public readonly VirtualCharSequence Text; | ||
public int Position; | ||
|
||
public RegexLexer(ImmutableArray<VirtualChar> text) : this() | ||
public RegexLexer(VirtualCharSequence text) : this() | ||
{ | ||
Text = text; | ||
} | ||
|
||
public VirtualChar CurrentChar => Position < Text.Length ? Text[Position] : new VirtualChar((char)0, default); | ||
|
||
public ImmutableArray<VirtualChar> GetSubPatternToCurrentPos(int start) | ||
public VirtualCharSequence GetSubPatternToCurrentPos(int start) | ||
=> GetSubPattern(start, Position); | ||
|
||
public ImmutableArray<VirtualChar> GetSubPattern(int start, int end) | ||
{ | ||
var result = ArrayBuilder<VirtualChar>.GetInstance(end - start); | ||
for (var i = start; i < end; i++) | ||
{ | ||
result.Add(Text[i]); | ||
} | ||
|
||
return result.ToImmutableAndFree(); | ||
} | ||
public VirtualCharSequence GetSubPattern(int start, int end) | ||
=> Text.GetSubSequence(TextSpan.FromBounds(start, end)); | ||
|
||
public RegexToken ScanNextToken(bool allowTrivia, RegexOptions options) | ||
{ | ||
var trivia = ScanLeadingTrivia(allowTrivia, options); | ||
if (Position == Text.Length) | ||
{ | ||
return CreateToken(RegexKind.EndOfFile, trivia, ImmutableArray<VirtualChar>.Empty); | ||
return CreateToken(RegexKind.EndOfFile, trivia, VirtualCharSequence.Empty); | ||
} | ||
|
||
var ch = this.CurrentChar; | ||
Position++; | ||
|
||
return CreateToken(GetKind(ch), trivia, ImmutableArray.Create(ch)); | ||
return CreateToken(GetKind(ch), trivia, Text.GetSubSequence(new TextSpan(Position - 1, 1))); | ||
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. allocation removed. |
||
} | ||
|
||
private static RegexKind GetKind(char ch) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Large source of allocations removed.
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.
now, when a Token/Trivia want to point at a range of characters, they can do it in an alloc-free manner. They just et a VirtualCharSequence (A struct) which is a sub-span of the original VirtualCharSequence.