< 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
 61916        public RangeCharSearchValues(char lowInclusive, char highInclusive)
 17        {
 61918            (_lowInclusive, _rangeInclusive, _highInclusive) = (lowInclusive, (char)(highInclusive - lowInclusive), high
 61919            _lowUint = lowInclusive;
 61920            _highMinusLow = (uint)(highInclusive - lowInclusive);
 61921        }
 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) =>
 12319638            value - _lowUint <= _highMinusLow;
 39
 40        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 41        internal override int IndexOfAny(ReadOnlySpan<char> span) =>
 247642            (PackedSpanHelpers.PackedIndexOfIsSupported && TShouldUsePacked.Value)
 247643                ? PackedSpanHelpers.IndexOfAnyInRange(ref MemoryMarshal.GetReference(span), _lowInclusive, _rangeInclusi
 247644                : SpanHelpers.NonPackedIndexOfAnyInRangeUnsignedNumber<ushort, SpanHelpers.DontNegate<ushort>>(
 247645                    ref Unsafe.As<char, ushort>(ref MemoryMarshal.GetReference(span)),
 247646                    _lowInclusive,
 247647                    _highInclusive,
 247648                    span.Length);
 49
 50        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 51        internal override int IndexOfAnyExcept(ReadOnlySpan<char> span) =>
 247652            (PackedSpanHelpers.PackedIndexOfIsSupported && TShouldUsePacked.Value)
 247653                ? PackedSpanHelpers.IndexOfAnyExceptInRange(ref MemoryMarshal.GetReference(span), _lowInclusive, _rangeI
 247654                : SpanHelpers.NonPackedIndexOfAnyInRangeUnsignedNumber<ushort, SpanHelpers.Negate<ushort>>(
 247655                    ref Unsafe.As<char, ushort>(ref MemoryMarshal.GetReference(span)),
 247656                    _lowInclusive,
 247657                    _highInclusive,
 247658                    span.Length);
 59
 60        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 61        internal override int LastIndexOfAny(ReadOnlySpan<char> span) =>
 123862            span.LastIndexOfAnyInRange(_lowInclusive, _highInclusive);
 63
 64        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 65        internal override int LastIndexOfAnyExcept(ReadOnlySpan<char> span) =>
 123866            span.LastIndexOfAnyExceptInRange(_lowInclusive, _highInclusive);
 67    }
 68}