Skip to content

Commit c6f1495

Browse files
committed
Add SearchValues<char> impl for two sets of 128 chars
1 parent a4407a1 commit c6f1495

9 files changed

+225
-98
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-1
Original file line numberDiff line numberDiff line change
@@ -2785,4 +2785,4 @@
27852785
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnaryPlusOperators.cs" />
27862786
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnsignedNumber.cs" />
27872787
</ItemGroup>
2788-
</Project>
2788+
</Project>

src/libraries/System.Private.CoreLib/src/System/SearchValues/Any2CharPackedIgnoreCaseSearchValues.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) =>
5353
[CompExactlyDependsOn(typeof(AdvSimd))]
5454
[CompExactlyDependsOn(typeof(PackedSimd))]
5555
internal override int LastIndexOfAny(ReadOnlySpan<char> span) =>
56-
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, IndexOfAnyAsciiSearcher.Default>(
56+
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, IndexOfAnyAsciiSearcher.Default, SearchValues.FalseConst>(
5757
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
5858

5959
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6060
[CompExactlyDependsOn(typeof(Ssse3))]
6161
[CompExactlyDependsOn(typeof(AdvSimd))]
6262
[CompExactlyDependsOn(typeof(PackedSimd))]
6363
internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) =>
64-
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.Negate, IndexOfAnyAsciiSearcher.Default>(
64+
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.Negate, IndexOfAnyAsciiSearcher.Default, SearchValues.FalseConst>(
6565
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
6666
}
6767
}

src/libraries/System.Private.CoreLib/src/System/SearchValues/AsciiByteSearchValues.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public AsciiByteSearchValues(ReadOnlySpan<byte> values) =>
1717
IndexOfAnyAsciiSearcher.ComputeAsciiState(values, out _state);
1818

1919
internal override byte[] GetValues() =>
20-
_state.Lookup.GetByteValues();
20+
_state.AsciiLookup.GetByteValues();
2121

2222
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2323
internal override bool ContainsCore(byte value) =>
24-
_state.Lookup.Contains(value);
24+
_state.AsciiLookup.Contains(value);
2525

2626
[CompExactlyDependsOn(typeof(Ssse3))]
2727
[CompExactlyDependsOn(typeof(AdvSimd))]
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics;
45
using System.Runtime.CompilerServices;
56
using System.Runtime.InteropServices;
67
using System.Runtime.Intrinsics.Arm;
@@ -9,67 +10,73 @@
910

1011
namespace System.Buffers
1112
{
12-
internal sealed class AsciiCharSearchValues<TOptimizations> : SearchValues<char>
13+
internal sealed class AsciiCharSearchValues<TOptimizations, TUseSecondBitmap> : SearchValues<char>
1314
where TOptimizations : struct, IndexOfAnyAsciiSearcher.IOptimizations
15+
where TUseSecondBitmap : struct, SearchValues.IRuntimeConst
1416
{
1517
private IndexOfAnyAsciiSearcher.AsciiState _state;
1618

17-
public AsciiCharSearchValues(ReadOnlySpan<char> values) =>
18-
IndexOfAnyAsciiSearcher.ComputeAsciiState(values, out _state);
19+
public AsciiCharSearchValues(IndexOfAnyAsciiSearcher.AsciiState state)
20+
{
21+
Debug.Assert(TUseSecondBitmap.Value == (state.SecondOffset != 0));
22+
Debug.Assert(TUseSecondBitmap.Value == (state.SecondBitmap != default));
23+
24+
_state = state;
25+
}
1926

2027
internal override char[] GetValues() =>
21-
_state.Lookup.GetCharValues();
28+
_state.AsciiLookup.GetCharValues();
2229

2330
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2431
internal override bool ContainsCore(char value) =>
25-
_state.Lookup.Contains128(value);
32+
_state.AsciiLookup.Contains128(value);
2633

2734
[CompExactlyDependsOn(typeof(Ssse3))]
2835
[CompExactlyDependsOn(typeof(AdvSimd))]
2936
[CompExactlyDependsOn(typeof(PackedSimd))]
3037
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3138
internal override int IndexOfAny(ReadOnlySpan<char> span) =>
32-
IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>(
39+
IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUseSecondBitmap>(
3340
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
3441

3542
[CompExactlyDependsOn(typeof(Ssse3))]
3643
[CompExactlyDependsOn(typeof(AdvSimd))]
3744
[CompExactlyDependsOn(typeof(PackedSimd))]
3845
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3946
internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) =>
40-
IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>(
47+
IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUseSecondBitmap>(
4148
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
4249

4350
[CompExactlyDependsOn(typeof(Ssse3))]
4451
[CompExactlyDependsOn(typeof(AdvSimd))]
4552
[CompExactlyDependsOn(typeof(PackedSimd))]
4653
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4754
internal override int LastIndexOfAny(ReadOnlySpan<char> span) =>
48-
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>(
55+
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUseSecondBitmap>(
4956
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
5057

5158
[CompExactlyDependsOn(typeof(Ssse3))]
5259
[CompExactlyDependsOn(typeof(AdvSimd))]
5360
[CompExactlyDependsOn(typeof(PackedSimd))]
5461
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5562
internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) =>
56-
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>(
63+
IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUseSecondBitmap>(
5764
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
5865

5966
[CompExactlyDependsOn(typeof(Ssse3))]
6067
[CompExactlyDependsOn(typeof(AdvSimd))]
6168
[CompExactlyDependsOn(typeof(PackedSimd))]
6269
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6370
internal override bool ContainsAny(ReadOnlySpan<char> span) =>
64-
IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>(
71+
IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUseSecondBitmap>(
6572
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
6673

6774
[CompExactlyDependsOn(typeof(Ssse3))]
6875
[CompExactlyDependsOn(typeof(AdvSimd))]
6976
[CompExactlyDependsOn(typeof(PackedSimd))]
7077
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7178
internal override bool ContainsAnyExcept(ReadOnlySpan<char> span) =>
72-
IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>(
79+
IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUseSecondBitmap>(
7380
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
7481
}
7582
}

0 commit comments

Comments
 (0)