| | | 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 | | |
| | | 6 | | namespace System.Buffers |
| | | 7 | | { |
| | | 8 | | internal sealed class RangeByteSearchValues : SearchValues<byte> |
| | | 9 | | { |
| | | 10 | | private readonly byte _lowInclusive, _highInclusive; |
| | | 11 | | private readonly uint _lowUint, _highMinusLow; |
| | | 12 | | |
| | 0 | 13 | | public RangeByteSearchValues(byte lowInclusive, byte highInclusive) |
| | | 14 | | { |
| | 0 | 15 | | (_lowInclusive, _highInclusive) = (lowInclusive, highInclusive); |
| | 0 | 16 | | _lowUint = lowInclusive; |
| | 0 | 17 | | _highMinusLow = (uint)(highInclusive - lowInclusive); |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | internal override byte[] GetValues() |
| | | 21 | | { |
| | 0 | 22 | | byte[] values = new byte[_highMinusLow + 1]; |
| | | 23 | | |
| | 0 | 24 | | int low = _lowInclusive; |
| | 0 | 25 | | for (int i = 0; i < values.Length; i++) |
| | | 26 | | { |
| | 0 | 27 | | values[i] = (byte)(low + i); |
| | | 28 | | } |
| | | 29 | | |
| | 0 | 30 | | return values; |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 34 | | internal override bool ContainsCore(byte value) => |
| | 0 | 35 | | value - _lowUint <= _highMinusLow; |
| | | 36 | | |
| | | 37 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 38 | | internal override int IndexOfAny(ReadOnlySpan<byte> span) => |
| | 0 | 39 | | span.IndexOfAnyInRange(_lowInclusive, _highInclusive); |
| | | 40 | | |
| | | 41 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 42 | | internal override int IndexOfAnyExcept(ReadOnlySpan<byte> span) => |
| | 0 | 43 | | span.IndexOfAnyExceptInRange(_lowInclusive, _highInclusive); |
| | | 44 | | |
| | | 45 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 46 | | internal override int LastIndexOfAny(ReadOnlySpan<byte> span) => |
| | 0 | 47 | | span.LastIndexOfAnyInRange(_lowInclusive, _highInclusive); |
| | | 48 | | |
| | | 49 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 50 | | internal override int LastIndexOfAnyExcept(ReadOnlySpan<byte> span) => |
| | 0 | 51 | | span.LastIndexOfAnyExceptInRange(_lowInclusive, _highInclusive); |
| | | 52 | | } |
| | | 53 | | } |
| | | 54 | | |