Minor code tweaks, remove readonly tricks
このコミットが含まれているのは:
1 親
bd1f921b37
コミット
f7c68ef287
4ファイル変更
+24
-18
検索条件に一致するファイルはありません
@@ -23,7 +23,7 @@ internal static class ArrayPoolBinaryWriterExtensions
|
||||
/// <param name="writer">The target <see cref="ArrayPoolBufferWriter{T}"/> instance to write data to.</param>
|
||||
/// <param name="value">The value to write.</param>
|
||||
/// <remarks>This method will just blit the data of <paramref name="value"/> into the target buffer.</remarks>
|
||||
public static unsafe void WriteRaw<T>(this in ArrayPoolBufferWriter<byte> writer, in T value)
|
||||
public static unsafe void WriteRaw<T>(this ref ArrayPoolBufferWriter<byte> writer, scoped in T value)
|
||||
where T : unmanaged
|
||||
{
|
||||
Span<byte> span = writer.GetSpan(sizeof(T));
|
||||
@@ -39,7 +39,7 @@ internal static class ArrayPoolBinaryWriterExtensions
|
||||
/// <typeparam name="T">The type of value to write.</typeparam>
|
||||
/// <param name="writer">The target <see cref="ArrayPoolBufferWriter{T}"/> instance to write data to.</param>
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static unsafe void WriteRaw<T>(this in ArrayPoolBufferWriter<T> writer, in T value)
|
||||
public static unsafe void WriteRaw<T>(this ref ArrayPoolBufferWriter<T> writer, scoped in T value)
|
||||
where T : unmanaged
|
||||
{
|
||||
Span<T> span = writer.GetSpan(1);
|
||||
@@ -55,7 +55,7 @@ internal static class ArrayPoolBinaryWriterExtensions
|
||||
/// <typeparam name="T">The type of values in the target writer.</typeparam>
|
||||
/// <param name="writer">The target <see cref="ArrayPoolBufferWriter{T}"/> instance to write data to.</param>
|
||||
/// <param name="data">The data to write.</param>
|
||||
public static void WriteRaw<T>(this in ArrayPoolBufferWriter<T> writer, ReadOnlySpan<T> data)
|
||||
public static void WriteRaw<T>(this ref ArrayPoolBufferWriter<T> writer, scoped ReadOnlySpan<T> data)
|
||||
where T : unmanaged
|
||||
{
|
||||
Span<T> span = writer.GetSpan(data.Length);
|
||||
@@ -71,7 +71,7 @@ internal static class ArrayPoolBinaryWriterExtensions
|
||||
/// </summary>
|
||||
/// <param name="writer">The target <see cref="ArrayPoolBufferWriter{T}"/> instance to write data to.</param>
|
||||
/// <param name="data">The data to write.</param>
|
||||
public static void WriteRaw(this in ArrayPoolBufferWriter<char> writer, string data)
|
||||
public static void WriteRaw(this ref ArrayPoolBufferWriter<char> writer, string data)
|
||||
{
|
||||
Span<char> span = writer.GetSpan(data.Length);
|
||||
|
||||
@@ -86,7 +86,7 @@ internal static class ArrayPoolBinaryWriterExtensions
|
||||
/// </summary>
|
||||
/// <param name="writer">The target <see cref="ArrayPoolBufferWriter{T}"/> instance to write data to.</param>
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteAsUtf8(this in ArrayPoolBufferWriter<byte> writer, int value)
|
||||
public static void WriteAsUtf8(this ref ArrayPoolBufferWriter<byte> writer, int value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
// Get a span of at least 10 elements (10 is the length of int.MaxValue as text)
|
||||
@@ -106,7 +106,7 @@ internal static class ArrayPoolBinaryWriterExtensions
|
||||
/// </summary>
|
||||
/// <param name="writer">The target <see cref="ArrayPoolBufferWriter{T}"/> instance to write data to.</param>
|
||||
/// <param name="text">The text to write.</param>
|
||||
public static void WriteAsUtf8(this in ArrayPoolBufferWriter<byte> writer, string text)
|
||||
public static void WriteAsUtf8(this ref ArrayPoolBufferWriter<byte> writer, string text)
|
||||
{
|
||||
int maximumByteSize = Encoding.UTF8.GetMaxByteCount(text.Length);
|
||||
|
||||
@@ -122,7 +122,7 @@ internal static class ArrayPoolBinaryWriterExtensions
|
||||
/// </summary>
|
||||
/// <param name="writer">The target <see cref="ArrayPoolBufferWriter{T}"/> instance to write data to.</param>
|
||||
/// <param name="value">The value to write.</param>
|
||||
public static void WriteAsUnicode(this in ArrayPoolBufferWriter<char> writer, int value)
|
||||
public static void WriteAsUnicode(this ref ArrayPoolBufferWriter<char> writer, int value)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
// Get a span of at least 10 elements (10 is the length of int.MaxValue as text)
|
||||
|
||||
@@ -35,7 +35,7 @@ internal ref struct ArrayPoolBufferWriter<T>
|
||||
/// <summary>
|
||||
/// The starting offset within <see cref="array"/>.
|
||||
/// </summary>
|
||||
private readonly int index;
|
||||
private int index;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ArrayPoolBufferWriter{T}"/> class.
|
||||
@@ -74,7 +74,7 @@ internal ref struct ArrayPoolBufferWriter<T>
|
||||
/// <para>Must be called after <see cref="GetSpan"/>.</para>
|
||||
/// <para>This and the methods below are <see langword="readonly"/> to enable mutating extensions.</para>
|
||||
/// </remarks>
|
||||
internal readonly void Advance(int count)
|
||||
internal void Advance(int count)
|
||||
{
|
||||
T[]? array = this.array;
|
||||
|
||||
@@ -93,7 +93,7 @@ internal ref struct ArrayPoolBufferWriter<T>
|
||||
ThrowArgumentExceptionForAdvancedTooFar();
|
||||
}
|
||||
|
||||
Unsafe.AsRef(in this.index) += count;
|
||||
this.index += count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -102,7 +102,7 @@ internal ref struct ArrayPoolBufferWriter<T>
|
||||
/// <param name="sizeHint">The capacity to request.</param>
|
||||
/// <returns>A <see cref="Span{T}"/> to write data to.</returns>
|
||||
[UnscopedRef]
|
||||
internal readonly Span<T> GetSpan(int sizeHint = 0)
|
||||
internal Span<T> GetSpan(int sizeHint = 0)
|
||||
{
|
||||
CheckBufferAndEnsureCapacity(sizeHint);
|
||||
|
||||
@@ -114,7 +114,7 @@ internal ref struct ArrayPoolBufferWriter<T>
|
||||
/// </summary>
|
||||
/// <param name="sizeHint">The minimum number of items to ensure space for in <see cref="array"/>.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private readonly void CheckBufferAndEnsureCapacity(int sizeHint)
|
||||
private void CheckBufferAndEnsureCapacity(int sizeHint)
|
||||
{
|
||||
T[]? array = this.array;
|
||||
|
||||
@@ -144,7 +144,7 @@ internal ref struct ArrayPoolBufferWriter<T>
|
||||
/// </summary>
|
||||
/// <param name="sizeHint">The minimum number of items to ensure space for in <see cref="array"/>.</param>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private readonly unsafe void ResizeBuffer(int sizeHint)
|
||||
private unsafe void ResizeBuffer(int sizeHint)
|
||||
{
|
||||
uint minimumSize = (uint)this.index + (uint)sizeHint;
|
||||
|
||||
@@ -164,7 +164,7 @@ internal ref struct ArrayPoolBufferWriter<T>
|
||||
|
||||
ArrayPool<T>.Shared.Return(this.array!);
|
||||
|
||||
Unsafe.AsRef(in this.array) = newArray;
|
||||
this.array = newArray;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -82,7 +82,7 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
|
||||
PixelShaderEffect.For<T>.Initialize(mapperFactory);
|
||||
|
||||
using ArrayPoolBufferWriter<char> writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize);
|
||||
ArrayPoolBufferWriter<char> writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize);
|
||||
|
||||
// Build the XML text
|
||||
writer.WriteRaw("""
|
||||
@@ -263,6 +263,8 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
|
||||
effectId = PixelShaderEffect.For<T>.Id;
|
||||
}
|
||||
|
||||
writer.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -342,7 +344,7 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
|
||||
PixelShaderEffect.For<T>.Initialize(mapperFactory);
|
||||
|
||||
using ArrayPoolBufferWriter<byte> writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize);
|
||||
ArrayPoolBufferWriter<byte> writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize);
|
||||
|
||||
// Blob id
|
||||
writer.WriteRaw(D2D1EffectRegistrationData.V1.BlobId);
|
||||
@@ -514,7 +516,11 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
|
||||
effectId = PixelShaderEffect.For<T>.Id;
|
||||
|
||||
return writer.WrittenSpan.ToArray();
|
||||
byte[] registrationBlob = writer.WrittenSpan.ToArray();
|
||||
|
||||
writer.Dispose();
|
||||
|
||||
return registrationBlob;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -44,7 +44,7 @@ public ref struct ArrayPoolStringBuilder
|
||||
/// Gets the data written to the underlying buffer so far, as a <see cref="ReadOnlySpan{T}"/>.
|
||||
/// </summary>
|
||||
[UnscopedRef]
|
||||
public ReadOnlySpan<char> WrittenSpan
|
||||
public readonly ReadOnlySpan<char> WrittenSpan
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => new(this.array, 0, this.index);
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする