-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improves whitespace and identifier parsing to match the spec (using Unicode 15.0) * Optimize whitespace and identifier parsing in the BMP range
- Loading branch information
Showing
9 changed files
with
1,450 additions
and
1,918 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Esprima; | ||
|
||
internal readonly partial struct CharRange | ||
{ | ||
public CharRange(int start, int end) | ||
{ | ||
Start = start; | ||
End = end; | ||
} | ||
|
||
public readonly int Start; | ||
|
||
public readonly int End; /* Inclusive */ | ||
|
||
public int Length => End - Start + 1; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public bool Contains(int codePoint) => Start <= codePoint && codePoint <= End; | ||
|
||
internal static bool CharSetContains(int codePoint, int[] charSet, int[] rangeLengthLookup) | ||
{ | ||
Debug.Assert(codePoint is >= 0 and <= Character.UnicodeLastCodePoint); | ||
|
||
var codePointShifted = codePoint << 8; | ||
|
||
var index = Array.BinarySearch(charSet, codePointShifted); | ||
if (index >= 0 | ||
|| (index = ~index) < charSet.Length && DecodeCharRange(charSet[index], rangeLengthLookup).Contains(codePoint) | ||
|| index > 0 && DecodeCharRange(charSet[--index], rangeLengthLookup).Contains(codePoint)) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private static CharRange DecodeCharRange(int data, int[] rangeLengths) | ||
{ | ||
var start = data >> 8; | ||
return new CharRange(start, start + rangeLengths[data & 0xFF]); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.