-
-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add NET 8 target for Jint * switch to NET 8 for tests, benchmarks and REPL * add SearchValues polyfill
- Loading branch information
Showing
24 changed files
with
130 additions
and
115 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
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
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 |
---|---|---|
@@ -1,12 +1,21 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Jint; | ||
|
||
internal static class Polyfills | ||
{ | ||
#if NETFRAMEWORK || NETSTANDARD2_0 | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal static bool Contains(this string source, char c) => source.IndexOf(c) != -1; | ||
#endif | ||
|
||
#if NETFRAMEWORK | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal static bool Contains(this ReadOnlySpan<string> source, string c) => source.IndexOf(c) != -1; | ||
#endif | ||
|
||
#if NETFRAMEWORK || NETSTANDARD2_0 | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal static bool StartsWith(this string source, char c) => source.Length > 0 && source[0] == c; | ||
#endif | ||
} |
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,44 @@ | ||
#if !NET8_0_OR_GREATER | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
namespace System.Buffers; | ||
|
||
internal static class SearchValues | ||
{ | ||
internal static SearchValues<char> Create(string input) => new(input.AsSpan()); | ||
internal static SearchValues<char> Create(ReadOnlySpan<char> input) => new(input); | ||
} | ||
|
||
internal sealed class SearchValues<T> | ||
{ | ||
private readonly bool[] _data; | ||
private readonly char _min; | ||
private readonly char _max; | ||
|
||
internal SearchValues(ReadOnlySpan<char> input) | ||
{ | ||
_min = char.MaxValue; | ||
_max = char.MinValue; | ||
foreach (var c in input) | ||
{ | ||
_min = (char) Math.Min(_min, c); | ||
_max = (char) Math.Max(_max, c); | ||
} | ||
|
||
_data = new bool[_max - _min + 1]; | ||
foreach (var c in input) | ||
{ | ||
_data[c - _min] = true; | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public bool Contains(char c) | ||
{ | ||
var i = (uint) (c - _min); | ||
var temp = _data; | ||
return i < temp.Length && temp[i]; | ||
} | ||
} | ||
#endif |
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.