diff --git a/src/ComputeSharp.Core/Helpers/TryWriteFormatInterpolatedStringHandler.cs b/src/ComputeSharp.Core/Helpers/TryWriteFormatInterpolatedStringHandler.cs deleted file mode 100644 index 0aec4d5b..00000000 --- a/src/ComputeSharp.Core/Helpers/TryWriteFormatInterpolatedStringHandler.cs +++ /dev/null @@ -1,256 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Runtime.InteropServices; - -namespace System.Runtime.CompilerServices; - -/// -/// Provides a handler used by the language compiler to format interpolated strings into character spans. -/// -[InterpolatedStringHandler] -internal ref struct TryWriteFormatInterpolatedStringHandler -{ - /// - /// The destination buffer. - /// - private readonly Span destination; - - /// - /// The format to use to print individual values to the target buffer. - /// - private readonly ReadOnlySpan format; - - /// - /// The value of , as a . - /// - private string? formatAsString; - - /// - /// Optional provider to pass to calls. - /// - private readonly IFormatProvider? formatProvider; - - /// - /// The number of characters written to . - /// - private int position; - - /// - /// Indicates whether all formatting operations have succeeded. - /// - private bool success; - - /// - /// Whether provides an . - /// - private readonly bool hasCustomFormatter; - - /// - /// Creates a handler used to write an interpolated string into a . - /// - /// The number of constant characters outside of interpolation expressions in the interpolated string. - /// The number of interpolation expressions in the interpolated string. - /// The destination buffer. - /// The format to use, if available. - /// An object that supplies culture-specific formatting information. - /// Upon return, true if the destination may be long enough to support the formatting, or false if it won't be. - /// This is intended to be called only by compiler-generated code. Arguments are not validated as they'd otherwise be for members intended to be used directly. - public TryWriteFormatInterpolatedStringHandler(int literalLength, int formattedCount, Span destination, ReadOnlySpan format, IFormatProvider? formatProvider, out bool shouldAppend) - { - this.destination = destination; - this.format = format; - this.formatAsString = null; - this.formatProvider = formatProvider; - this.position = 0; - this.success = shouldAppend = destination.Length >= literalLength; - this.hasCustomFormatter = formatProvider is not null && FormatInterpolatedStringHandler.HasCustomFormatter(formatProvider); - } - - /// - /// Writes the specified interpolated string to the character span. - /// - /// The span to which the interpolated string should be formatted. - /// The format to use, if available. - /// An object that supplies culture-specific formatting information. - /// The interpolated string. - /// The number of characters written to the span. - /// true if the entire interpolated string could be formatted successfully; otherwise, false. - public static bool TryWrite( - Span destination, - ReadOnlySpan format, - IFormatProvider? formatProvider, - [InterpolatedStringHandlerArgument("destination", "format", "formatProvider")] ref TryWriteFormatInterpolatedStringHandler handler, - out int charsWritten) - { - if (handler.success) - { - charsWritten = handler.position; - - return true; - } - - charsWritten = 0; - - return false; - } - - /// - /// Writes the specified to the handler. - /// - /// The to write. - /// Whether the value could be formatted to the span. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool AppendLiteral(string value) - { - if (value.Length == 1) - { - Span destination = this.destination; - int pos = this.position; - - if ((uint)pos < (uint)destination.Length) - { - destination[pos] = value[0]; - - this.position = pos + 1; - - return true; - } - - return Fail(); - } - - if (value.Length == 2) - { - Span destination = this.destination; - int pos = this.position; - - if ((uint)pos < destination.Length - 1) - { - Unsafe.WriteUnaligned( - ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetReference(destination), pos)), -#if NET6_0_OR_GREATER - Unsafe.ReadUnaligned(ref Unsafe.As(ref Unsafe.AsRef(in value.GetPinnableReference())))); -#else - Unsafe.ReadUnaligned(ref Unsafe.As(ref MemoryMarshal.GetReference(value.AsSpan())))); -#endif - - this.position = pos + 2; - - return true; - } - - return Fail(); - } - - return AppendStringDirect(value); - } - - /// - /// Writes the specified string to the handler. - /// - /// The string to write. - /// Whether the value could be appended to the span. - private bool AppendStringDirect(string value) - { -#if NET6_0_OR_GREATER - if (value.TryCopyTo(this.destination.Slice(this.position))) -#else - if (value.AsSpan().TryCopyTo(this.destination.Slice(this.position))) -#endif - { - this.position += value.Length; - return true; - } - - return Fail(); - } - - /// - /// Writes the specified value to the handler. - /// - /// The value to write. - public bool AppendFormatted(T value) -#if NET6_0_OR_GREATER - where T : ISpanFormattable -#else - where T : IFormattable -#endif - { - if (this.hasCustomFormatter) - { - return AppendCustomFormatter(value, this.formatAsString ??= this.format.ToString()); - } - -#if NET6_0_OR_GREATER - if (value.TryFormat(this.destination.Slice(this.position), out int charsWritten, this.format, this.formatProvider)) - { - this.position += charsWritten; - - return true; - } - - return Fail(); -#else - return AppendStringDirect(value.ToString(this.formatAsString ??= this.format.ToString(), this.formatProvider)); -#endif - } - - /// - /// Writes the specified value to the handler. - /// - /// The value to write. - public bool AppendFormatted(string? value) - { - if (this.hasCustomFormatter) - { - return AppendCustomFormatter(value, format: null); - } - - if (value is null) - { - return true; - } - -#if NET6_0_OR_GREATER - if (value.TryCopyTo(this.destination.Slice(this.position))) -#else - if (value.AsSpan().TryCopyTo(this.destination.Slice(this.position))) -#endif - { - this.position += value.Length; - - return true; - } - - return Fail(); - } - - /// - /// Formats the value using the custom formatter from the provider. - /// - /// The value to write. - /// The format string. - [MethodImpl(MethodImplOptions.NoInlining)] - private bool AppendCustomFormatter(T value, string? format) - { - ICustomFormatter? formatter = (ICustomFormatter?)this.formatProvider?.GetFormat(typeof(ICustomFormatter)); - - if (formatter is not null && formatter.Format(format, value, this.formatProvider) is string customFormatted) - { - return AppendStringDirect(customFormatted); - } - - return true; - } - - /// - /// Marks formatting as having failed and returns false. - /// - private bool Fail() - { - this.success = false; - - return false; - } -} \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs index b2393b2e..14e687d7 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs @@ -474,11 +474,7 @@ public unsafe partial struct Bool2 /// public override readonly string ToString() { -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[32], $"<{this.x != 0}, {this.y != 0}>"); -#else return $"<{this.x != 0}, {this.y != 0}>"; -#endif } #endif diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs index f118c8e0..11f81f83 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs @@ -1740,11 +1740,7 @@ public unsafe partial struct Bool3 /// public override readonly string ToString() { -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[32], $"<{this.x != 0}, {this.y != 0}, {this.z != 0}>"); -#else return $"<{this.x != 0}, {this.y != 0}, {this.z != 0}>"; -#endif } #endif diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs index 51b833a2..8829f59c 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs @@ -4826,11 +4826,7 @@ public unsafe partial struct Bool4 /// public override readonly string ToString() { -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[32], $"<{this.x != 0}, {this.y != 0}, {this.z != 0}, {this.w != 0}>"); -#else return $"<{this.x != 0}, {this.y != 0}, {this.z != 0}, {this.w != 0}>"; -#endif } #endif diff --git a/src/ComputeSharp.Core/Primitives/Double/Double2.g.cs b/src/ComputeSharp.Core/Primitives/Double/Double2.g.cs index 7712ce9e..7ca7c16a 100644 --- a/src/ComputeSharp.Core/Primitives/Double/Double2.g.cs +++ b/src/ComputeSharp.Core/Primitives/Double/Double2.g.cs @@ -15,9 +15,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 8)] public unsafe partial struct Double2 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -481,36 +478,7 @@ public unsafe partial struct Double2 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}>"); -#else return $"<{this.x}{separator} {this.y}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/Double/Double3.g.cs b/src/ComputeSharp.Core/Primitives/Double/Double3.g.cs index 3fb62e96..53b8e311 100644 --- a/src/ComputeSharp.Core/Primitives/Double/Double3.g.cs +++ b/src/ComputeSharp.Core/Primitives/Double/Double3.g.cs @@ -15,9 +15,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 8)] public unsafe partial struct Double3 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -1747,36 +1744,7 @@ public unsafe partial struct Double3 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}{separator} {this.z}>"); -#else return $"<{this.x}{separator} {this.y}{separator} {this.z}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}{separator} {this.z}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}{separator} {this.z}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/Double/Double4.g.cs b/src/ComputeSharp.Core/Primitives/Double/Double4.g.cs index 138da11f..40575dfb 100644 --- a/src/ComputeSharp.Core/Primitives/Double/Double4.g.cs +++ b/src/ComputeSharp.Core/Primitives/Double/Double4.g.cs @@ -15,9 +15,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 8)] public unsafe partial struct Double4 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -4833,36 +4830,7 @@ public unsafe partial struct Double4 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"); -#else return $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/Float/Float2.g.cs b/src/ComputeSharp.Core/Primitives/Float/Float2.g.cs index 51a3919d..137578c0 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float2.g.cs +++ b/src/ComputeSharp.Core/Primitives/Float/Float2.g.cs @@ -16,9 +16,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] public unsafe partial struct Float2 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -482,36 +479,7 @@ public unsafe partial struct Float2 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}>"); -#else return $"<{this.x}{separator} {this.y}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/Float/Float3.g.cs b/src/ComputeSharp.Core/Primitives/Float/Float3.g.cs index 76368312..05ed5679 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float3.g.cs +++ b/src/ComputeSharp.Core/Primitives/Float/Float3.g.cs @@ -16,9 +16,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 12, Pack = 4)] public unsafe partial struct Float3 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -1748,36 +1745,7 @@ public unsafe partial struct Float3 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}{separator} {this.z}>"); -#else return $"<{this.x}{separator} {this.y}{separator} {this.z}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}{separator} {this.z}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}{separator} {this.z}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/Float/Float4.g.cs b/src/ComputeSharp.Core/Primitives/Float/Float4.g.cs index aa1205fd..adb432ed 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float4.g.cs +++ b/src/ComputeSharp.Core/Primitives/Float/Float4.g.cs @@ -16,9 +16,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] public unsafe partial struct Float4 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -4834,36 +4831,7 @@ public unsafe partial struct Float4 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"); -#else return $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/Int/Int2.g.cs b/src/ComputeSharp.Core/Primitives/Int/Int2.g.cs index b8fc1714..77773ce2 100644 --- a/src/ComputeSharp.Core/Primitives/Int/Int2.g.cs +++ b/src/ComputeSharp.Core/Primitives/Int/Int2.g.cs @@ -16,9 +16,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] public unsafe partial struct Int2 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -482,36 +479,7 @@ public unsafe partial struct Int2 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}>"); -#else return $"<{this.x}{separator} {this.y}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/Int/Int3.g.cs b/src/ComputeSharp.Core/Primitives/Int/Int3.g.cs index d158b264..431f4b38 100644 --- a/src/ComputeSharp.Core/Primitives/Int/Int3.g.cs +++ b/src/ComputeSharp.Core/Primitives/Int/Int3.g.cs @@ -16,9 +16,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 12, Pack = 4)] public unsafe partial struct Int3 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -1748,36 +1745,7 @@ public unsafe partial struct Int3 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}{separator} {this.z}>"); -#else return $"<{this.x}{separator} {this.y}{separator} {this.z}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}{separator} {this.z}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}{separator} {this.z}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/Int/Int4.g.cs b/src/ComputeSharp.Core/Primitives/Int/Int4.g.cs index faaf3357..7edef8f7 100644 --- a/src/ComputeSharp.Core/Primitives/Int/Int4.g.cs +++ b/src/ComputeSharp.Core/Primitives/Int/Int4.g.cs @@ -16,9 +16,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] public unsafe partial struct Int4 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -4834,36 +4831,7 @@ public unsafe partial struct Int4 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"); -#else return $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt2.g.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt2.g.cs index fa64a737..2c251318 100644 --- a/src/ComputeSharp.Core/Primitives/UInt/UInt2.g.cs +++ b/src/ComputeSharp.Core/Primitives/UInt/UInt2.g.cs @@ -15,9 +15,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] public unsafe partial struct UInt2 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -481,36 +478,7 @@ public unsafe partial struct UInt2 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}>"); -#else return $"<{this.x}{separator} {this.y}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt3.g.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt3.g.cs index 26353ec6..3114bde1 100644 --- a/src/ComputeSharp.Core/Primitives/UInt/UInt3.g.cs +++ b/src/ComputeSharp.Core/Primitives/UInt/UInt3.g.cs @@ -15,9 +15,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 12, Pack = 4)] public unsafe partial struct UInt3 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -1747,36 +1744,7 @@ public unsafe partial struct UInt3 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}{separator} {this.z}>"); -#else return $"<{this.x}{separator} {this.y}{separator} {this.z}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}{separator} {this.z}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}{separator} {this.z}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt4.g.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt4.g.cs index 15977e8a..77e37b45 100644 --- a/src/ComputeSharp.Core/Primitives/UInt/UInt4.g.cs +++ b/src/ComputeSharp.Core/Primitives/UInt/UInt4.g.cs @@ -15,9 +15,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] public unsafe partial struct UInt4 -#if NET6_0_OR_GREATER - : ISpanFormattable -#endif { /// /// A private buffer to which the undefined properties will point to. @@ -4833,36 +4830,7 @@ public unsafe partial struct UInt4 { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"); -#else return $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<{this.x}{separator} {this.y}{separator} {this.z}{separator} {this.w}>", - out charsWritten); } #endif diff --git a/src/ComputeSharp.Core/Primitives/VectorType.ttinclude b/src/ComputeSharp.Core/Primitives/VectorType.ttinclude index 186df432..c6711b8b 100644 --- a/src/ComputeSharp.Core/Primitives/VectorType.ttinclude +++ b/src/ComputeSharp.Core/Primitives/VectorType.ttinclude @@ -51,7 +51,6 @@ void GenerateVectorProperties(string typeName, int elementSize) bool isBoolType = hlslElementTypeName == "bool"; string fieldElementTypeName = isBoolType ? "int" : hlslElementTypeName; int i = int.Parse(Regex.Match(typeName, @"\d+$").Value); - string formattable = elementTypeName == "Bool" ? "" : "ISpanFormattable"; List namespaces = new List { @@ -88,16 +87,6 @@ namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = <#=(elementSize * i)#>, Pack = <#=elementSize#>)] public unsafe partial struct <#=typeName#> -<# - if (formattable != "") - { -#> -#if NET6_0_OR_GREATER - : <#=formattable#> -#endif -<# - } -#> { /// /// A private buffer to which the undefined properties will point to. @@ -258,11 +247,7 @@ public unsafe partial struct <#=typeName#> /// public override readonly string ToString() { -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[32], $"<<#=string.Join(", ", "xyzw".Take(i).Select(c => $"{{this.{c} != 0}}"))#>>"); -#else return $"<<#=string.Join(", ", "xyzw".Take(i).Select(c => $"{{this.{c} != 0}}"))#>>"; -#endif } <# } @@ -274,36 +259,7 @@ public unsafe partial struct <#=typeName#> { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; -#if NET6_0_OR_GREATER - return string.Create(null, stackalloc char[64], $"<<#=string.Join("{separator} ", "xyzw".Take(i).Select(c => $"{{this.{c}}}"))#>>"); -#else return $"<<#=string.Join("{separator} ", "xyzw".Take(i).Select(c => $"{{this.{c}}}"))#>>"; -#endif - } - - /// - public readonly string ToString(string? format, IFormatProvider? formatProvider) - { - string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; - - return FormatInterpolatedStringHandler.Create( - format, - formatProvider, - stackalloc char[64], - $"<<#=string.Join("{separator} ", "xyzw".Take(i).Select(c => $"{{this.{c}}}"))#>>"); - } - - /// - public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) - { - string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; - - return TryWriteFormatInterpolatedStringHandler.TryWrite( - destination, - format, - provider, - $"<<#=string.Join("{separator} ", "xyzw".Take(i).Select(c => $"{{this.{c}}}"))#>>", - out charsWritten); } <# }