IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
RefUtils.cs
Go to the documentation of this file.
1#if NET6_0_OR_GREATER
2
3using System;
5using System.Runtime.InteropServices;
6
8{
9 static class RefUtils
10 {
11 [MethodImpl(MethodImplOptions.AggressiveInlining)]
12 public static ref T Post<T>(ref Span<T> data, nint byteOffset) where T : struct
13 {
14 ref T element = ref MemoryMarshal.GetReference(data);
15#if NET8_0_OR_GREATER
16 data = new(ref Unsafe.AddByteOffset(ref element, byteOffset));
17#else
18 data = MemoryMarshal.CreateSpan(ref Unsafe.AddByteOffset(ref element, byteOffset), 1);
19#endif
20 return ref element;
21 }
22
23 [MethodImpl(MethodImplOptions.AggressiveInlining)]
24 public static ref T Post<T>(ref ReadOnlySpan<T> data, nint byteOffset) where T : struct
25 {
26 ref T element = ref MemoryMarshal.GetReference(data);
27#if NET8_0_OR_GREATER
28 data = new(in Unsafe.AddByteOffset(ref element, byteOffset));
29#else
30 data = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AddByteOffset(ref element, byteOffset), 1);
31#endif
32 return ref element;
33 }
34 }
35}
36
37#endif