Skip to content

Commit 13abb44

Browse files
authored
Add SearchValues<char> implementation for two sets of 128 chars (#103216)
1 parent 38c120d commit 13abb44

File tree

5 files changed

+498
-22
lines changed

5 files changed

+498
-22
lines changed

src/libraries/System.Memory/tests/Span/SearchValues.cs

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public static IEnumerable<object[]> Values_MemberData()
8282
{
8383
yield return Pair(value);
8484
yield return Pair('a' + value);
85+
yield return Pair('\uFF00' + value);
8586

8687
// Test some more duplicates
8788
if (value.Length > 0)

src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems

+1
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@
441441
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Any1SearchValues.cs" />
442442
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Any2SearchValues.cs" />
443443
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\Any3SearchValues.cs" />
444+
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\AsciiWithSecondSetCharSearchValues.cs" />
444445
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\BitVector256.cs" />
445446
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\ProbabilisticMapState.cs" />
446447
<Compile Include="$(MSBuildThisFileDirectory)System\SearchValues\ProbabilisticWithAsciiCharSearchValues.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Runtime.CompilerServices;
5+
using System.Runtime.InteropServices;
6+
using System.Runtime.Intrinsics.Arm;
7+
using System.Runtime.Intrinsics.Wasm;
8+
using System.Runtime.Intrinsics.X86;
9+
10+
namespace System.Buffers
11+
{
12+
internal sealed class AsciiWithSecondSetCharSearchValues<TOptimizations> : SearchValues<char>
13+
where TOptimizations : struct, IndexOfAnyAsciiSearcher.IOptimizations
14+
{
15+
private IndexOfAnyAsciiSearcher.AsciiWithSecondSetState _state;
16+
17+
public AsciiWithSecondSetCharSearchValues(IndexOfAnyAsciiSearcher.AsciiWithSecondSetState state) =>
18+
_state = state;
19+
20+
internal override char[] GetValues() =>
21+
_state.Lookup.GetValues();
22+
23+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
24+
internal override bool ContainsCore(char value) =>
25+
_state.Lookup.FastContains(value);
26+
27+
[CompExactlyDependsOn(typeof(Ssse3))]
28+
[CompExactlyDependsOn(typeof(AdvSimd))]
29+
[CompExactlyDependsOn(typeof(PackedSimd))]
30+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
31+
internal override int IndexOfAny(ReadOnlySpan<char> span) =>
32+
IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>(
33+
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
34+
35+
[CompExactlyDependsOn(typeof(Ssse3))]
36+
[CompExactlyDependsOn(typeof(AdvSimd))]
37+
[CompExactlyDependsOn(typeof(PackedSimd))]
38+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
39+
internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) =>
40+
IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>(
41+
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
42+
43+
[CompExactlyDependsOn(typeof(Ssse3))]
44+
[CompExactlyDependsOn(typeof(AdvSimd))]
45+
[CompExactlyDependsOn(typeof(PackedSimd))]
46+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
47+
internal override int LastIndexOfAny(ReadOnlySpan<char> span) =>
48+
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>(
49+
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
50+
51+
[CompExactlyDependsOn(typeof(Ssse3))]
52+
[CompExactlyDependsOn(typeof(AdvSimd))]
53+
[CompExactlyDependsOn(typeof(PackedSimd))]
54+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
55+
internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) =>
56+
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>(
57+
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
58+
59+
[CompExactlyDependsOn(typeof(Ssse3))]
60+
[CompExactlyDependsOn(typeof(AdvSimd))]
61+
[CompExactlyDependsOn(typeof(PackedSimd))]
62+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
63+
internal override bool ContainsAny(ReadOnlySpan<char> span) =>
64+
IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>(
65+
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
66+
67+
[CompExactlyDependsOn(typeof(Ssse3))]
68+
[CompExactlyDependsOn(typeof(AdvSimd))]
69+
[CompExactlyDependsOn(typeof(PackedSimd))]
70+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
71+
internal override bool ContainsAnyExcept(ReadOnlySpan<char> span) =>
72+
IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>(
73+
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
74+
}
75+
}

0 commit comments

Comments
 (0)