-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Contains and IndexOfValue(3 chars)
- Loading branch information
Showing
11 changed files
with
453 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/libraries/System.Private.CoreLib/src/System/IndexOfAnyValues/IndexOfAny3CharValues.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace System.Buffers | ||
{ | ||
internal sealed class IndexOfAny3CharValue<TShouldUsePacked> : IndexOfAnyValues<char> | ||
where TShouldUsePacked : struct, IndexOfAnyValues.IRuntimeConst | ||
{ | ||
private char _e0, _e1, _e2; | ||
|
||
public IndexOfAny3CharValue(char value0, char value1, char value2) => | ||
(_e0, _e1, _e2) = (value0, value1, value2); | ||
|
||
internal override char[] GetValues() => new[] { _e0, _e1, _e2 }; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override bool ContainsCore(char value) => | ||
value == _e0 || value == _e1 || value == _e2; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override int IndexOfAny(ReadOnlySpan<char> span) => | ||
TShouldUsePacked.Value | ||
? PackedSpanHelpers.PackedIndexOfAny(ref MemoryMarshal.GetReference(span), _e0, _e1, _e2, span.Length) | ||
: SpanHelpers.NonPackedIndexOfAnyValueType<short, SpanHelpers.DontNegate<short>>( | ||
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), | ||
Unsafe.As<char, short>(ref _e0), | ||
Unsafe.As<char, short>(ref _e1), | ||
Unsafe.As<char, short>(ref _e2), | ||
span.Length); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) => | ||
TShouldUsePacked.Value | ||
? PackedSpanHelpers.PackedIndexOfAnyExcept(ref MemoryMarshal.GetReference(span), _e0, _e1, _e2, span.Length) | ||
: SpanHelpers.NonPackedIndexOfAnyValueType<short, SpanHelpers.Negate<short>>( | ||
ref Unsafe.As<char, short>(ref MemoryMarshal.GetReference(span)), | ||
Unsafe.As<char, short>(ref _e0), | ||
Unsafe.As<char, short>(ref _e1), | ||
Unsafe.As<char, short>(ref _e2), | ||
span.Length); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override int LastIndexOfAny(ReadOnlySpan<char> span) => | ||
span.LastIndexOfAny(_e0, _e1, _e2); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) => | ||
span.LastIndexOfAnyExcept(_e0, _e1, _e2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.