Files
Fishery/Source/FisheryLib/SpanCompatExtensions.cs
localavaster fdff6b048a fix crash
2026-04-14 00:11:03 -06:00

26 lines
626 B
C#

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace FisheryLib;
internal static class SpanCompatExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe ref T DangerousGetPinnableReference<T>(this Span<T> span)
{
if (span.Length == 0)
return ref Unsafe.AsRef<T>((void*)1);
return ref span[0];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe ref T DangerousGetPinnableReference<T>(this ReadOnlySpan<T> span)
{
if (span.Length == 0)
return ref Unsafe.AsRef<T>((void*)1);
return ref Unsafe.AsRef(in span[0]);
}
}