< Summary

Information
Class: ZeroC.Slice.Internal.SpanEnumerator
Assembly: ZeroC.Slice
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/ZeroC.Slice/Internal/SpanEnumerator.cs
Tag: 275_13775359185
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 68
Line coverage: 100%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage
100%
Covered methods: 3
Total methods: 3
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Current()50%22100%
MoveNext()100%1010100%
.ctor(...)100%11100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/ZeroC.Slice/Internal/SpanEnumerator.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3namespace ZeroC.Slice.Internal;
 4
 5/// <summary>An enumerator over one or more <see cref="Span{T}" /> of bytes. Used by <see cref="BitSequenceWriter" />.
 6/// </summary>
 7internal ref struct SpanEnumerator
 8{
 9    /// <summary>Gets the current span.</summary>
 1484610    internal readonly Span<byte> Current => _position >= 0 ? _currentSpan :
 1484611        throw new InvalidOperationException("The enumerator was not initialized.");
 12
 13    private Span<byte> _currentSpan;
 14    private readonly Span<byte> _firstSpan;
 15    private readonly Span<byte> _secondSpan;
 16    private readonly IList<Memory<byte>>? _additionalMemory;
 17    private int _position;
 18
 19    /// <summary>Moves to the next span.</summary>
 20    /// <returns><see langword="true" /> when the operation was successful, and <see langword="false" /> when the
 21    /// current span is the last span.</returns>
 22    internal bool MoveNext()
 131423    {
 131424        switch (_position)
 25        {
 26            case -1:
 115427                _position = 0;
 115428                _currentSpan = _firstSpan;
 115429                return true;
 30            case 0:
 3831                if (_secondSpan.Length > 0)
 3532                {
 3533                    _position = 1;
 3534                    _currentSpan = _secondSpan;
 3535                    return true;
 36                }
 37                else
 338                {
 339                    return false;
 40                }
 41            default:
 12242                if (_additionalMemory is not null && _additionalMemory.Count > _position - 1)
 10943                {
 10944                    _position += 1;
 10945                    _currentSpan = _additionalMemory[_position - 2].Span;
 10946                    return true;
 47                }
 48                else
 1349                {
 1350                    return false;
 51                }
 52        }
 131453    }
 54
 55    /// <summary>Constructs a span enumerator.</summary>
 56    internal SpanEnumerator(
 57        Span<byte> firstSpan,
 58        Span<byte> secondSpan = default,
 59        IList<Memory<byte>>? additionalMemory = null)
 115460    {
 115461        _firstSpan = firstSpan;
 115462        _secondSpan = secondSpan;
 115463        _additionalMemory = additionalMemory;
 64
 115465        _currentSpan = default;
 115466        _position = -1;
 115467    }
 68}