< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 19
Coverable lines: 19
Total lines: 48
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
GetString(...)0%220%
GetNextHandle(...)0%440%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Internal/UserStringHeap.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.Reflection.Internal;
 5
 6namespace System.Reflection.Metadata.Ecma335
 7{
 8    internal readonly struct UserStringHeap
 9    {
 10        internal readonly MemoryBlock Block;
 11
 12        public UserStringHeap(MemoryBlock block)
 013        {
 014            this.Block = block;
 015        }
 16
 17        internal string GetString(UserStringHandle handle)
 018        {
 19            int offset, size;
 020            if (!Block.PeekHeapValueOffsetAndSize(handle.GetHeapOffset(), out offset, out size))
 021            {
 022                return string.Empty;
 23            }
 24
 25            // Spec: Furthermore, there is an additional terminal byte (so all byte counts are odd, not even).
 26            // The size in the blob header is the length of the string in bytes + 1.
 027            return Block.PeekUtf16(offset, size & ~1);
 028        }
 29
 30        internal UserStringHandle GetNextHandle(UserStringHandle handle)
 031        {
 32            int offset, size;
 033            if (!Block.PeekHeapValueOffsetAndSize(handle.GetHeapOffset(), out offset, out size))
 034            {
 035                return default(UserStringHandle);
 36            }
 37
 038            int nextIndex = offset + size;
 039            if (nextIndex >= Block.Length)
 040            {
 041                return default(UserStringHandle);
 42            }
 43
 044            return UserStringHandle.FromOffset(nextIndex);
 045        }
 46    }
 47}
 48