< Summary

Line coverage
81%
Covered lines: 22
Uncovered lines: 5
Coverable lines: 27
Total lines: 69
Line coverage: 81.4%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

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
 103316        public RangeCharSearchValues(char lowInclusive, char highInclusive)
 17        {
 103318            (_lowInclusive, _rangeInclusive, _highInclusive) = (lowInclusive, (char)(highInclusive - lowInclusive), high
 103319            _lowUint = lowInclusive;
 103320            _highMinusLow = (uint)(highInclusive - lowInclusive);
 103321        }
 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) =>
 22165238            value - _lowUint <= _highMinusLow;
 39
 40        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 41        internal override int IndexOfAny(ReadOnlySpan<char> span) =>
 413242            (PackedSpanHelpers.PackedIndexOfIsSupported && TShouldUsePacked.Value)
 413243                ? PackedSpanHelpers.IndexOfAnyInRange(ref MemoryMarshal.GetReference(span), _lowInclusive, _rangeInclusi
 413244                : SpanHelpers.NonPackedIndexOfAnyInRangeUnsignedNumber<ushort, SpanHelpers.DontNegate<ushort>>(
 413245                    ref Unsafe.As<char, ushort>(ref MemoryMarshal.GetReference(span)),
 413246                    _lowInclusive,
 413247                    _highInclusive,
 413248                    span.Length);
 49
 50        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 51        internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) =>
 413252            (PackedSpanHelpers.PackedIndexOfIsSupported && TShouldUsePacked.Value)
 413253                ? PackedSpanHelpers.IndexOfAnyExceptInRange(ref MemoryMarshal.GetReference(span), _lowInclusive, _rangeI
 413254                : SpanHelpers.NonPackedIndexOfAnyInRangeUnsignedNumber<ushort, SpanHelpers.Negate<ushort>>(
 413255                    ref Unsafe.As<char, ushort>(ref MemoryMarshal.GetReference(span)),
 413256                    _lowInclusive,
 413257                    _highInclusive,
 413258                    span.Length);
 59
 60        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 61        internal override int LastIndexOfAny(ReadOnlySpan<char> span) =>
 206662            span.LastIndexOfAnyInRange(_lowInclusive, _highInclusive);
 63
 64        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 65        internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) =>
 206666            span.LastIndexOfAnyExceptInRange(_lowInclusive, _highInclusive);
 67    }
 68}
 69