Skip to content

Commit

Permalink
Added back IParameterSpanData
Browse files Browse the repository at this point in the history
Corrected ToSpan for non string values
  • Loading branch information
Aragas committed Nov 14, 2023
1 parent 68a9b02 commit f1c2222
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/BUTR.NativeAOT.Shared/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public unsafe interface IParameterSpanFormattable<TSelf>
{
static abstract ReadOnlySpan<char> ToSpan(TSelf* ptr);
}
public unsafe interface IParameterSpanData<TSelf, TValue>
where TSelf : unmanaged, IParameterSpanData<TSelf, TValue>
where TValue : unmanaged
{
static abstract ReadOnlySpan<TValue> ToSpan(TSelf* ptr, int length);
}
public unsafe interface IParameterNonPtr<TSelf> where TSelf : unmanaged, IParameterNonPtr<TSelf> { }
public unsafe interface IParameterRawPtr<TSelf, TValue>
where TSelf : unmanaged, IParameterRawPtr<TSelf, TValue>
Expand Down Expand Up @@ -249,6 +255,7 @@ public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnly
public readonly unsafe struct param_data :
IParameter<param_data>,
IParameterSpanFormattable<param_data>,
IParameterSpanData<param_data, byte>,
IParameterRawPtr<param_data, byte>,
IParameterIntPtr<param_data>,
IFormattable
Expand All @@ -257,7 +264,9 @@ public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnly
public static implicit operator byte*(param_data ptr) => (byte*) &ptr;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlySpan<char> ToSpan(param_data* ptr) => $"[{new IntPtr(ptr->Value):x16}]";
public static ReadOnlySpan<char> ToSpan(param_data* ptr) => ptr->ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlySpan<byte> ToSpan(param_data* ptr, int length) => new(ptr->Value, length);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IntPtr IParameterIntPtr<param_data>.ToPtr(param_data* ptr) => new(ptr);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -279,7 +288,7 @@ public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnly
public static implicit operator byte*(param_callback ptr) => (byte*) &ptr;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlySpan<char> ToSpan(param_callback* ptr) => $"[{new IntPtr(ptr->CallbackPtr):x16}]";
public static ReadOnlySpan<char> ToSpan(param_callback* ptr) => ptr->ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IntPtr IParameterIntPtr<param_callback>.ToPtr(param_callback* ptr) => new(ptr);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down

0 comments on commit f1c2222

Please sign in to comment.