| | | 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.Runtime.CompilerServices; |
| | | 6 | | using System.Runtime.InteropServices; |
| | | 7 | | using System.Runtime.Intrinsics.X86; |
| | | 8 | | |
| | | 9 | | namespace System.Buffers |
| | | 10 | | { |
| | | 11 | | internal sealed class Any1CharPackedIgnoreCaseSearchValues : SearchValues<char> |
| | | 12 | | { |
| | | 13 | | // While this most commonly applies to ASCII letters, it also works for other values that differ by 0x20 (e.g. " |
| | | 14 | | // _lowerCase is therefore not necessarily a lower case ASCII letter, but just the higher value (the one with th |
| | | 15 | | private readonly char _lowerCase, _upperCase; |
| | | 16 | | private readonly uint _lowerCaseUint; |
| | | 17 | | |
| | 0 | 18 | | public Any1CharPackedIgnoreCaseSearchValues(char value) |
| | | 19 | | { |
| | 0 | 20 | | Debug.Assert((value | 0x20) == value); |
| | | 21 | | |
| | 0 | 22 | | _lowerCase = value; |
| | 0 | 23 | | _upperCase = (char)(value & ~0x20); |
| | 0 | 24 | | _lowerCaseUint = value; |
| | 0 | 25 | | } |
| | | 26 | | |
| | | 27 | | internal override char[] GetValues() => |
| | 0 | 28 | | [_upperCase, _lowerCase]; |
| | | 29 | | |
| | | 30 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 31 | | internal override bool ContainsCore(char value) => |
| | 0 | 32 | | (uint)(value | 0x20) == _lowerCaseUint; |
| | | 33 | | |
| | | 34 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 35 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 36 | | internal override int IndexOfAny(ReadOnlySpan<char> span) => |
| | 0 | 37 | | PackedSpanHelpers.IndexOfAnyIgnoreCase(ref MemoryMarshal.GetReference(span), _lowerCase, span.Length); |
| | | 38 | | |
| | | 39 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 40 | | [CompExactlyDependsOn(typeof(Sse2))] |
| | | 41 | | internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) => |
| | 0 | 42 | | PackedSpanHelpers.IndexOfAnyExceptIgnoreCase(ref MemoryMarshal.GetReference(span), _lowerCase, span.Length); |
| | | 43 | | |
| | | 44 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 45 | | internal override int LastIndexOfAny(ReadOnlySpan<char> span) => |
| | 0 | 46 | | span.LastIndexOfAny(_lowerCase, _upperCase); |
| | | 47 | | |
| | | 48 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 49 | | internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) => |
| | 0 | 50 | | span.LastIndexOfAnyExcept(_lowerCase, _upperCase); |
| | | 51 | | } |
| | | 52 | | } |
| | | 53 | | |