File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
src/libraries/System.Private.CoreLib/src/System/IndexOfAnyValues Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 3
3
4
4
using System . Runtime . CompilerServices ;
5
5
using System . Runtime . InteropServices ;
6
+ using System . Runtime . Intrinsics ;
6
7
7
8
namespace System . Buffers
8
9
{
@@ -11,8 +12,18 @@ internal sealed class IndexOfAnyCharValuesProbabilistic : IndexOfAnyValues<char>
11
12
private ProbabilisticMap _map ;
12
13
private readonly string _values ;
13
14
14
- public unsafe IndexOfAnyCharValuesProbabilistic ( ReadOnlySpan < char > values )
15
+ public IndexOfAnyCharValuesProbabilistic ( scoped ReadOnlySpan < char > values )
15
16
{
17
+ if ( Vector128 . IsHardwareAccelerated && values . Length < 8 )
18
+ {
19
+ // ProbabilisticMap does a Span.Contains check to confirm potential matches.
20
+ // If we have fewer than 8 values, pad them with existing ones to make the verification faster.
21
+ Span < char > newValues = stackalloc char [ 8 ] ;
22
+ newValues . Fill ( values [ 0 ] ) ;
23
+ values . CopyTo ( newValues ) ;
24
+ values = newValues ;
25
+ }
26
+
16
27
_values = new string ( values ) ;
17
28
_map = new ProbabilisticMap ( _values ) ;
18
29
}
You can’t perform that action at this time.
0 commit comments