< Summary

Information
Class: System.Buffers.RangeCharSearchValues<T>
Assembly: System.Private.CoreLib
File(s): D:\runner\runtime\src\libraries\System.Private.CoreLib\src\System\SearchValues\RangeCharSearchValues.cs
Line coverage
81%
Covered lines: 22
Uncovered lines: 5
Coverable lines: 27
Total lines: 68
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)

D:\runner\runtime\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
 62616        public RangeCharSearchValues(char lowInclusive, char highInclusive)
 17        {
 62618            (_lowInclusive, _rangeInclusive, _highInclusive) = (lowInclusive, (char)(highInclusive - lowInclusive), high
 62619            _lowUint = lowInclusive;
 62620            _highMinusLow = (uint)(highInclusive - lowInclusive);
 62621        }
 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) =>
 12375038            value - _lowUint <= _highMinusLow;
 39
 40        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 41        internal override int IndexOfAny(ReadOnlySpan<char> span) =>
 250442            (PackedSpanHelpers.PackedIndexOfIsSupported && TShouldUsePacked.Value)
 250443                ? PackedSpanHelpers.IndexOfAnyInRange(ref MemoryMarshal.GetReference(span), _lowInclusive, _rangeInclusi
 250444                : SpanHelpers.NonPackedIndexOfAnyInRangeUnsignedNumber<ushort, SpanHelpers.DontNegate<ushort>>(
 250445                    ref Unsafe.As<char, ushort>(ref MemoryMarshal.GetReference(span)),
 250446                    _lowInclusive,
 250447                    _highInclusive,
 250448                    span.Length);
 49
 50        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 51        internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) =>
 250452            (PackedSpanHelpers.PackedIndexOfIsSupported && TShouldUsePacked.Value)
 250453                ? PackedSpanHelpers.IndexOfAnyExceptInRange(ref MemoryMarshal.GetReference(span), _lowInclusive, _rangeI
 250454                : SpanHelpers.NonPackedIndexOfAnyInRangeUnsignedNumber<ushort, SpanHelpers.Negate<ushort>>(
 250455                    ref Unsafe.As<char, ushort>(ref MemoryMarshal.GetReference(span)),
 250456                    _lowInclusive,
 250457                    _highInclusive,
 250458                    span.Length);
 59
 60        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 61        internal override int LastIndexOfAny(ReadOnlySpan<char> span) =>
 125262            span.LastIndexOfAnyInRange(_lowInclusive, _highInclusive);
 63
 64        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 65        internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) =>
 125266            span.LastIndexOfAnyExceptInRange(_lowInclusive, _highInclusive);
 67    }
 68}