|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
| 4 | +using System.Diagnostics; |
4 | 5 | using System.Runtime.CompilerServices;
|
5 | 6 | using System.Runtime.InteropServices;
|
6 | 7 | using System.Runtime.Intrinsics.Arm;
|
|
9 | 10 |
|
10 | 11 | namespace System.Buffers
|
11 | 12 | {
|
12 |
| - internal sealed class AsciiCharSearchValues<TOptimizations> : SearchValues<char> |
| 13 | + internal sealed class AsciiCharSearchValues<TOptimizations, TUseSecondBitmap> : SearchValues<char> |
13 | 14 | where TOptimizations : struct, IndexOfAnyAsciiSearcher.IOptimizations
|
| 15 | + where TUseSecondBitmap : struct, SearchValues.IRuntimeConst |
14 | 16 | {
|
15 | 17 | private IndexOfAnyAsciiSearcher.AsciiState _state;
|
16 | 18 |
|
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 | + } |
19 | 26 |
|
20 | 27 | internal override char[] GetValues() =>
|
21 |
| - _state.Lookup.GetCharValues(); |
| 28 | + _state.AsciiLookup.GetCharValues(); |
22 | 29 |
|
23 | 30 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
24 | 31 | internal override bool ContainsCore(char value) =>
|
25 |
| - _state.Lookup.Contains128(value); |
| 32 | + _state.AsciiLookup.Contains128(value); |
26 | 33 |
|
27 | 34 | [CompExactlyDependsOn(typeof(Ssse3))]
|
28 | 35 | [CompExactlyDependsOn(typeof(AdvSimd))]
|
29 | 36 | [CompExactlyDependsOn(typeof(PackedSimd))]
|
30 | 37 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
31 | 38 | internal override int IndexOfAny(ReadOnlySpan<char> span) =>
|
32 |
| - IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>( |
| 39 | + IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUseSecondBitmap>( |
33 | 40 | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
|
34 | 41 |
|
35 | 42 | [CompExactlyDependsOn(typeof(Ssse3))]
|
36 | 43 | [CompExactlyDependsOn(typeof(AdvSimd))]
|
37 | 44 | [CompExactlyDependsOn(typeof(PackedSimd))]
|
38 | 45 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
39 | 46 | internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) =>
|
40 |
| - IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>( |
| 47 | + IndexOfAnyAsciiSearcher.IndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUseSecondBitmap>( |
41 | 48 | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
|
42 | 49 |
|
43 | 50 | [CompExactlyDependsOn(typeof(Ssse3))]
|
44 | 51 | [CompExactlyDependsOn(typeof(AdvSimd))]
|
45 | 52 | [CompExactlyDependsOn(typeof(PackedSimd))]
|
46 | 53 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
47 | 54 | internal override int LastIndexOfAny(ReadOnlySpan<char> span) =>
|
48 |
| - IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>( |
| 55 | + IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUseSecondBitmap>( |
49 | 56 | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
|
50 | 57 |
|
51 | 58 | [CompExactlyDependsOn(typeof(Ssse3))]
|
52 | 59 | [CompExactlyDependsOn(typeof(AdvSimd))]
|
53 | 60 | [CompExactlyDependsOn(typeof(PackedSimd))]
|
54 | 61 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
55 | 62 | internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) =>
|
56 |
| - IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>( |
| 63 | + IndexOfAnyAsciiSearcher.LastIndexOfAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUseSecondBitmap>( |
57 | 64 | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
|
58 | 65 |
|
59 | 66 | [CompExactlyDependsOn(typeof(Ssse3))]
|
60 | 67 | [CompExactlyDependsOn(typeof(AdvSimd))]
|
61 | 68 | [CompExactlyDependsOn(typeof(PackedSimd))]
|
62 | 69 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
63 | 70 | internal override bool ContainsAny(ReadOnlySpan<char> span) =>
|
64 |
| - IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations>( |
| 71 | + IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.DontNegate, TOptimizations, TUseSecondBitmap>( |
65 | 72 | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
|
66 | 73 |
|
67 | 74 | [CompExactlyDependsOn(typeof(Ssse3))]
|
68 | 75 | [CompExactlyDependsOn(typeof(AdvSimd))]
|
69 | 76 | [CompExactlyDependsOn(typeof(PackedSimd))]
|
70 | 77 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
71 | 78 | internal override bool ContainsAnyExcept(ReadOnlySpan<char> span) =>
|
72 |
| - IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations>( |
| 79 | + IndexOfAnyAsciiSearcher.ContainsAny<IndexOfAnyAsciiSearcher.Negate, TOptimizations, TUseSecondBitmap>( |
73 | 80 | ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), span.Length, ref _state);
|
74 | 81 | }
|
75 | 82 | }
|
0 commit comments