< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 69
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
GetValues()0%220%
ContainsCore(...)100%110%
IndexOfAny(...)0%440%
IndexOfAnyExcept(...)0%440%
LastIndexOfAny(...)100%110%
LastIndexOfAnyExcept(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/SearchValues/RangeCharSearchValues.cs

#LineLine coverage
 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
 4using System.Runtime.CompilerServices;
 5using System.Runtime.InteropServices;
 6
 7namespace System.Buffers
 8{
 9    internal sealed class RangeCharSearchValues<TShouldUsePacked> : SearchValues<char>
 10        where TShouldUsePacked : struct, SearchValues.IRuntimeConst
 11    {
 12        private readonly char _rangeInclusive;
 13        private char _lowInclusive, _highInclusive;
 14        private readonly uint _lowUint, _highMinusLow;
 15
 016        public RangeCharSearchValues(char lowInclusive, char highInclusive)
 17        {
 018            (_lowInclusive, _rangeInclusive, _highInclusive) = (lowInclusive, (char)(highInclusive - lowInclusive), high
 019            _lowUint = lowInclusive;
 020            _highMinusLow = (uint)(highInclusive - lowInclusive);
 021        }
 22
 23        internal override char[] GetValues()
 24        {
 025            char[] values = new char[_rangeInclusive + 1];
 26
 027            int low = _lowInclusive;
 028            for (int i = 0; i < values.Length; i++)
 29            {
 030                values[i] = (char)(low + i);
 31            }
 32
 033            return values;
 34        }
 35
 36        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 37        internal override bool ContainsCore(char value) =>
 038            value - _lowUint <= _highMinusLow;
 39
 40        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 41        internal override int IndexOfAny(ReadOnlySpan<char> span) =>
 042            (PackedSpanHelpers.PackedIndexOfIsSupported && TShouldUsePacked.Value)
 043                ? PackedSpanHelpers.IndexOfAnyInRange(ref MemoryMarshal.GetReference(span), _lowInclusive, _rangeInclusi
 044                : SpanHelpers.NonPackedIndexOfAnyInRangeUnsignedNumber<ushort, SpanHelpers.DontNegate<ushort>>(
 045                    ref Unsafe.As<char, ushort>(ref MemoryMarshal.GetReference(span)),
 046                    _lowInclusive,
 047                    _highInclusive,
 048                    span.Length);
 49
 50        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 51        internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) =>
 052            (PackedSpanHelpers.PackedIndexOfIsSupported && TShouldUsePacked.Value)
 053                ? PackedSpanHelpers.IndexOfAnyExceptInRange(ref MemoryMarshal.GetReference(span), _lowInclusive, _rangeI
 054                : SpanHelpers.NonPackedIndexOfAnyInRangeUnsignedNumber<ushort, SpanHelpers.Negate<ushort>>(
 055                    ref Unsafe.As<char, ushort>(ref MemoryMarshal.GetReference(span)),
 056                    _lowInclusive,
 057                    _highInclusive,
 058                    span.Length);
 59
 60        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 61        internal override int LastIndexOfAny(ReadOnlySpan<char> span) =>
 062            span.LastIndexOfAnyInRange(_lowInclusive, _highInclusive);
 63
 64        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 65        internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) =>
 066            span.LastIndexOfAnyExceptInRange(_lowInclusive, _highInclusive);
 67    }
 68}
 69