• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

neon-sunset / U8String / 6005208900

28 Aug 2023 09:36PM UTC coverage: 18.096% (-0.2%) from 18.326%
6005208900

push

github

neon-sunset
feat: Extend NativeU8String and restructure solution to account for increased line count, add roadmap draft

134 of 1050 branches covered (0.0%)

Branch coverage included in aggregate %.

1058 of 1058 new or added lines in 25 files covered. (100.0%)

478 of 2332 relevant lines covered (20.5%)

35305.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Implementations/Native/NativeU8String.Construction.cs
1
using System.Diagnostics;
2
using System.Runtime.InteropServices;
3

4
namespace U8Primitives;
5

6
public unsafe readonly partial struct NativeU8String
7
{
8
    public NativeU8String(ReadOnlySpan<byte> value)
9
    {
10
        if (value.Length > 0)
×
11
        {
12
            U8String.Validate(value);
×
13
            this = new(value, skipValidation: true);
×
14
        }
15
    }
×
16

17
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
18
    internal NativeU8String(ReadOnlySpan<byte> value, bool skipValidation)
19
    {
20
        Debug.Assert(skipValidation);
21

22
        if (value.Length > 0)
×
23
        {
24
            if (value[^1] is not (byte)'\0')
×
25
            {
26
                // TODO: dedup ops and improve or just leave it as is?
27
                _ptr = (byte*)NativeMemory.Alloc((uint)value.Length + 1);
×
28
                _length = (nint)(uint)value.Length + 1;
×
29
                _ptr[value.Length] = (byte)'\0';
×
30
            }
31
            else
32
            {
33
                _ptr = (byte*)NativeMemory.Alloc((uint)value.Length);
×
34
                _length = (nint)(uint)value.Length;
×
35
            }
36

37
            value.CopyTo(MemoryMarshal.CreateSpan(ref _ptr[0], value.Length));
×
38
        }
39
    }
×
40

41
    public static NativeU8String CreateUnchecked(ReadOnlySpan<byte> value)
42
    {
43
        return new(value, skipValidation: true);
×
44
    }
45

46
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
47
    public static NativeU8String CreateFromPinnedUnchecked(ReadOnlySpan<byte> value)
48
    {
49
        var ptr = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(value));
×
50
        var length = (nint)(uint)value.Length;
×
51

52
        return new(ptr, length);
×
53
    }
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc