Move primitives to ComputeSharp.Core

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:03:14 +02:00
1 親 cc298770ca
コミット e48949cd48
78ファイル変更
+369 -245

検索条件に一致するファイルはありません

+36
ファイルの表示
@@ -0,0 +1,36 @@
using System;
using System.Runtime.CompilerServices;
namespace ComputeSharp.Core.NetStandard.System.Runtime.InteropServices;
/// <summary>
/// A polyfill type that mirrors some methods from <see cref="MemoryMarshal"/> on .NET 6.
/// </summary>
internal static class MemoryMarshal
{
/// <inheritdoc cref="global::System.Runtime.InteropServices.MemoryMarshal.GetReference{T}(Span{T})"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T GetReference<T>(Span<T> span)
{
return ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(span);
}
/// <inheritdoc cref="global::System.Runtime.InteropServices.MemoryMarshal.GetReference{T}(ReadOnlySpan{T})"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T GetReference<T>(ReadOnlySpan<T> span)
{
return ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(span);
}
/// <summary>
/// Creates a new <see cref="Span{T}"/> from a given reference.
/// </summary>
/// <typeparam name="T">The type of reference to wrap.</typeparam>
/// <param name="value">The target reference.</param>
/// <param name="length">The length of the <see cref="Span{T}"/> to create.</param>
/// <returns>A new <see cref="Span{T}"/> wrapping <paramref name="value"/>.</returns>
public static unsafe Span<T> CreateSpan<T>(ref T value, int length)
{
return new(Unsafe.AsPointer(ref value), length);
}
}
@@ -0,0 +1,28 @@
namespace System.Runtime.CompilerServices;
/// <summary>
/// Indicates which arguments to a method involving an interpolated string handler should be passed to that handler.
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
public sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="InterpolatedStringHandlerArgumentAttribute"/> class.
/// </summary>
/// <param name="argument">The name of the argument that should be passed to the handler.</param>
/// <remarks><see langword="null"/> may be used as the name of the receiver in an instance method.</remarks>
public InterpolatedStringHandlerArgumentAttribute(string argument) => Arguments = new string[] { argument };
/// <summary>
/// Initializes a new instance of the <see cref="InterpolatedStringHandlerArgumentAttribute"/> class.
/// </summary>
/// <param name="arguments">The names of the arguments that should be passed to the handler.</param>
/// <remarks><see langword="null"/> may be used as the name of the receiver in an instance method.</remarks>
public InterpolatedStringHandlerArgumentAttribute(params string[] arguments) => Arguments = arguments;
/// <summary>
/// Gets the names of the arguments that should be passed to the handler.
/// </summary>
/// <remarks><see langword="null"/> may be used as the name of the receiver in an instance method.</remarks>
public string[] Arguments { get; }
}
@@ -0,0 +1,9 @@
namespace System.Runtime.CompilerServices;
/// <summary>
/// Indicates the attributed type is to be used as an interpolated string handler.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
public sealed class InterpolatedStringHandlerAttribute : Attribute
{
}
+18
ファイルの表示
@@ -0,0 +1,18 @@
using System;
using System.Runtime.InteropServices;
namespace ComputeSharp.Core.NetStandard.System.Runtime.CompilerServices;
/// <summary>
/// A polyfill type that mirrors some methods from <see cref="RuntimeHelpers"/> on .NET 5.
/// </summary>
internal static class RuntimeHelpers
{
/// <summary>
/// Allocates some memory tied to the lifetime of a specific type.
/// </summary>
/// <param name="type">The type to associate the memory to.</param>
/// <param name="size">The size in byte of the memory to allocate.</param>
/// <returns>A pointer to the allocated memory.</returns>
public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) => Marshal.AllocHGlobal(size);
}