| | | 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.Diagnostics; |
| | | 5 | | using System.Numerics; |
| | | 6 | | using System.Runtime.CompilerServices; |
| | | 7 | | using System.Runtime.InteropServices; |
| | | 8 | | |
| | | 9 | | namespace System.Buffers |
| | | 10 | | { |
| | | 11 | | internal sealed class Any2SearchValues<T, TImpl> : SearchValues<T> |
| | | 12 | | where T : struct, IEquatable<T> |
| | | 13 | | where TImpl : struct, INumber<TImpl> |
| | | 14 | | { |
| | | 15 | | private readonly TImpl _e0, _e1; |
| | | 16 | | |
| | 1767 | 17 | | public unsafe Any2SearchValues(ReadOnlySpan<TImpl> values) |
| | | 18 | | { |
| | 1767 | 19 | | Debug.Assert(sizeof(T) == sizeof(TImpl)); |
| | 1767 | 20 | | Debug.Assert(values.Length == 2); |
| | 1767 | 21 | | (_e0, _e1) = (values[0], values[1]); |
| | 1767 | 22 | | } |
| | | 23 | | |
| | | 24 | | internal override unsafe T[] GetValues() |
| | | 25 | | { |
| | 0 | 26 | | TImpl e0 = _e0, e1 = _e1; |
| | 0 | 27 | | return [*(T*)&e0, *(T*)&e1]; |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 31 | | internal override unsafe bool ContainsCore(T value) => |
| | 346063 | 32 | | *(TImpl*)&value == _e0 || *(TImpl*)&value == _e1; |
| | | 33 | | |
| | | 34 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 35 | | internal override int IndexOfAny(ReadOnlySpan<T> span) => |
| | 7068 | 36 | | SpanHelpers.NonPackedIndexOfAnyValueType<TImpl, SpanHelpers.DontNegate<TImpl>>(ref Unsafe.As<T, TImpl>(ref M |
| | | 37 | | |
| | | 38 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 39 | | internal override int IndexOfAnyExcept(ReadOnlySpan<T> span) => |
| | 7068 | 40 | | SpanHelpers.NonPackedIndexOfAnyValueType<TImpl, SpanHelpers.Negate<TImpl>>(ref Unsafe.As<T, TImpl>(ref Memor |
| | | 41 | | |
| | | 42 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 43 | | internal override int LastIndexOfAny(ReadOnlySpan<T> span) => |
| | 3534 | 44 | | SpanHelpers.LastIndexOfAnyValueType(ref Unsafe.As<T, TImpl>(ref MemoryMarshal.GetReference(span)), _e0, _e1, |
| | | 45 | | |
| | | 46 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 47 | | internal override int LastIndexOfAnyExcept(ReadOnlySpan<T> span) => |
| | 3534 | 48 | | SpanHelpers.LastIndexOfAnyExceptValueType(ref Unsafe.As<T, TImpl>(ref MemoryMarshal.GetReference(span)), _e0 |
| | | 49 | | } |
| | | 50 | | } |
| | | 51 | | |