< Summary - Results for net9.0, Release

Information
Class: LockCheck.Linux.InodeInfo
Assembly: LockCheck
File(s): /home/runner/work/LockCheck/LockCheck/src/LockCheck/Linux/InodeInfo.cs
Tag: 96_11660771111
Line coverage
75%
Covered lines: 18
Uncovered lines: 6
Coverable lines: 24
Total lines: 95
Line coverage: 75%
Branch coverage
68%
Covered branches: 11
Total branches: 16
Branch coverage: 68.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TryParse(...)68.75%19.341676.47%
.ctor(...)100%11100%
get_MajorDeviceId()100%210%
get_MinorDeviceId()100%210%
get_INodeNumber()100%11100%

File(s)

/home/runner/work/LockCheck/LockCheck/src/LockCheck/Linux/InodeInfo.cs

#LineLine coverage
 1using System;
 2using System.Globalization;
 3
 4namespace LockCheck.Linux;
 5
 6internal readonly struct InodeInfo
 7{
 8    public static bool TryParse(ReadOnlySpan<char> field, out InodeInfo value)
 9    {
 10#if NET9_0_OR_GREATER
 11        // This implementation *look* more complex and thus slower, but is actually faster:
 12        //
 13        // | Method | Mean     | Error    | StdDev   | Ratio | RatioSD | Code Size | Allocated | Alloc Ratio |
 14        // |------- |---------:|---------:|---------:|------:|--------:|----------:|----------:|------------:|
 15        // | Old    | 71.97 ns | 1.462 ns | 1.900 ns |  1.00 |    0.04 |   1,604 B |         - |          NA |
 16        // | NET9.0 | 51.40 ns | 0.800 ns | 0.668 ns |  0.71 |    0.02 |   1,355 B |         - |          NA |
 17
 218        int num = 0;
 219        int major = 0;
 220        int minor = 0;
 221        long number = 0;
 22
 223        foreach (var range in field.Split(':'))
 24        {
 225            var fieldContent = field[range].Trim();
 26
 27            switch (num)
 28            {
 29                case 0:
 230                    if (!int.TryParse(fieldContent, NumberStyles.HexNumber, null, out major))
 31                    {
 032                        goto fail;
 33                    }
 34                    break;
 35                case 1:
 236                    if (!int.TryParse(fieldContent, NumberStyles.HexNumber, null, out minor))
 37                    {
 038                        goto fail;
 39                    }
 40                    break;
 41                case 2:
 242                    if (!long.TryParse(fieldContent, NumberStyles.Integer, null, out number))
 43                    {
 44                        goto fail;
 45                    }
 46                    break;
 47            }
 48
 249            if (++num > 2)
 50            {
 51                // Ignore additional fields
 52                break;
 53            }
 54        }
 55
 256        if (num < 2)
 57        {
 58            // Not enough fields
 59            goto fail;
 60        }
 61
 262        value = new InodeInfo(major, minor, number);
 263        return true;
 64fail:
 065        value = default;
 066        return false;
 67#else
 68        int count = field.Count(':') + 1;
 69        Span<Range> ranges = count < 128 ? stackalloc Range[count] : new Range[count];
 70        int num = MemoryExtensions.Split(field, ranges, ':', StringSplitOptions.TrimEntries);
 71        if (num < 3 ||
 72            !int.TryParse(field[ranges[0]], NumberStyles.HexNumber, null, out int major) ||
 73            !int.TryParse(field[ranges[1]], NumberStyles.HexNumber, null, out int minor) ||
 74            !long.TryParse(field[ranges[2]], NumberStyles.Integer, null, out long number))
 75        {
 76            value = default;
 77            return false;
 78        }
 79
 80        value = new InodeInfo(major, minor, number);
 81        return true;
 82#endif
 83    }
 84
 85    private InodeInfo(int majorDeviceId, int minorDeviceId, long iNodeNumber)
 86    {
 287        MajorDeviceId = majorDeviceId;
 288        MinorDeviceId = minorDeviceId;
 289        INodeNumber = iNodeNumber;
 290    }
 91
 092    public readonly int MajorDeviceId { get; }
 093    public readonly int MinorDeviceId { get; }
 294    public readonly long INodeNumber { get; }
 95}