Merge pull request #391 from Sergio0694/dev/roslyn-updates

Minor code tweaks, remove readonly tricks
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2022-10-22 13:01:28 -07:00
コミット c5334fd719
19ファイル変更
+60 -49

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

+2 -2
ファイルの表示
@@ -40,8 +40,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.4.0-2.final" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.4.0-2.final" PrivateAssets="all" />
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.4.0-4.final" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.4.0-4.final" PrivateAssets="all" />
</ItemGroup>
<!-- Centralized location for all generated artifacts -->
+1 -1
ファイルの表示
@@ -63,7 +63,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0-2.final" PrivateAssets="all" Pack="false" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0-4.final" PrivateAssets="all" Pack="false" />
</ItemGroup>
<ItemGroup>
+1 -1
ファイルの表示
@@ -95,7 +95,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0-2.final" PrivateAssets="all" Pack="false" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0-4.final" PrivateAssets="all" Pack="false" />
</ItemGroup>
<ItemGroup>
+7 -7
ファイルの表示
@@ -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)
+24 -18
ファイルの表示
@@ -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.
@@ -59,7 +59,7 @@ internal ref struct ArrayPoolBufferWriter<T>
if (array is null)
{
ThrowObjectDisposedException();
ArrayPoolBufferWriterHelpers.ThrowObjectDisposedException();
}
return array.AsSpan(0, this.index);
@@ -74,26 +74,26 @@ 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;
if (array is null)
{
ThrowObjectDisposedException();
ArrayPoolBufferWriterHelpers.ThrowObjectDisposedException();
}
if (count < 0)
{
ThrowArgumentOutOfRangeExceptionForNegativeCount();
ArrayPoolBufferWriterHelpers.ThrowArgumentOutOfRangeExceptionForNegativeCount();
}
if (this.index > array.Length - count)
{
ThrowArgumentExceptionForAdvancedTooFar();
ArrayPoolBufferWriterHelpers.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,18 +114,18 @@ 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;
if (array is null)
{
ThrowObjectDisposedException();
ArrayPoolBufferWriterHelpers.ThrowObjectDisposedException();
}
if (sizeHint < 0)
{
ThrowArgumentOutOfRangeExceptionForNegativeSizeHint();
ArrayPoolBufferWriterHelpers.ThrowArgumentOutOfRangeExceptionForNegativeSizeHint();
}
if (sizeHint == 0)
@@ -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/>
@@ -181,12 +181,18 @@ internal ref struct ArrayPoolBufferWriter<T>
ArrayPool<T>.Shared.Return(array);
}
}
/// <summary>
/// Private helpers for <see cref="ArrayPoolBufferWriter{T}"/>.
/// </summary>
file static class ArrayPoolBufferWriterHelpers
{
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the requested count is negative.
/// </summary>
[DoesNotReturn]
private static void ThrowArgumentOutOfRangeExceptionForNegativeCount()
public static void ThrowArgumentOutOfRangeExceptionForNegativeCount()
{
throw new ArgumentOutOfRangeException("count", "The count can't be a negative value.");
}
@@ -195,7 +201,7 @@ internal ref struct ArrayPoolBufferWriter<T>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the size hint is negative.
/// </summary>
[DoesNotReturn]
private static void ThrowArgumentOutOfRangeExceptionForNegativeSizeHint()
public static void ThrowArgumentOutOfRangeExceptionForNegativeSizeHint()
{
throw new ArgumentOutOfRangeException("sizeHint", "The size hint can't be a negative value.");
}
@@ -204,16 +210,16 @@ internal ref struct ArrayPoolBufferWriter<T>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the requested count is negative.
/// </summary>
[DoesNotReturn]
private static void ThrowArgumentExceptionForAdvancedTooFar()
public static void ThrowArgumentExceptionForAdvancedTooFar()
{
throw new ArgumentException("The buffer writer has advanced too far.");
}
/// <summary>
/// Throws an <see cref="ObjectDisposedException"/> when <see cref="array"/> is <see langword="null"/>.
/// Throws an <see cref="ObjectDisposedException"/> when the array is <see langword="null"/>.
/// </summary>
[DoesNotReturn]
private static void ThrowObjectDisposedException()
public static void ThrowObjectDisposedException()
{
throw new ObjectDisposedException("The current buffer has already been disposed.");
}
+10 -5
ファイルの表示
@@ -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>
@@ -338,11 +340,9 @@ public static unsafe class D2D1PixelShaderEffect
public static ReadOnlyMemory<byte> GetRegistrationBlob<T>(ID2D1TransformMapperFactory<T>? mapperFactory, out Guid effectId)
where T : unmanaged, ID2D1PixelShader
{
effectId = default;
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);
@@ -512,9 +512,14 @@ public static unsafe class D2D1PixelShaderEffect
// Effect factory
writer.WriteRaw((nint)PixelShaderEffect.For<T>.Factory);
byte[] registrationBlob = writer.WrittenSpan.ToArray();
writer.Dispose();
// Extract the effect id (the same that was encoded in the registration blob)
effectId = PixelShaderEffect.For<T>.Id;
return writer.WrittenSpan.ToArray();
return registrationBlob;
}
/// <summary>
+1 -1
ファイルの表示
@@ -85,7 +85,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0-2.final" PrivateAssets="all" Pack="false" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0-4.final" PrivateAssets="all" Pack="false" />
</ItemGroup>
<ItemGroup>
+1 -1
ファイルの表示
@@ -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);
+1 -1
ファイルの表示
@@ -4,7 +4,7 @@ using System;
namespace TerraFX.Interop.Windows
{
internal partial struct BOOL : IComparable, IComparable<BOOL>, IEquatable<BOOL>, IFormattable
internal readonly partial struct BOOL : IComparable, IComparable<BOOL>, IEquatable<BOOL>, IFormattable
{
public readonly int Value;
+1 -1
ファイルの表示
@@ -4,7 +4,7 @@ using System;
namespace TerraFX.Interop.Windows
{
internal unsafe partial struct HANDLE : IComparable, IComparable<HANDLE>, IEquatable<HANDLE>, IFormattable
internal readonly unsafe partial struct HANDLE : IComparable, IComparable<HANDLE>, IEquatable<HANDLE>, IFormattable
{
public readonly void* Value;
+1 -1
ファイルの表示
@@ -4,7 +4,7 @@ using System;
namespace TerraFX.Interop.Windows
{
internal unsafe partial struct HRESULT : IComparable, IComparable<HRESULT>, IEquatable<HRESULT>, IFormattable
internal readonly unsafe partial struct HRESULT : IComparable, IComparable<HRESULT>, IEquatable<HRESULT>, IFormattable
{
public readonly int Value;
+1 -1
ファイルの表示
@@ -4,7 +4,7 @@ using System;
namespace TerraFX.Interop.Windows
{
internal unsafe partial struct HWND : IComparable, IComparable<HWND>, IEquatable<HWND>, IFormattable
internal readonly unsafe partial struct HWND : IComparable, IComparable<HWND>, IEquatable<HWND>, IFormattable
{
public readonly void* Value;
+1 -1
ファイルの表示
@@ -4,7 +4,7 @@ using System;
namespace TerraFX.Interop.Windows
{
internal unsafe partial struct LPARAM : IComparable, IComparable<LPARAM>, IEquatable<LPARAM>, IFormattable
internal readonly unsafe partial struct LPARAM : IComparable, IComparable<LPARAM>, IEquatable<LPARAM>, IFormattable
{
public readonly nint Value;
+1 -1
ファイルの表示
@@ -4,7 +4,7 @@ using System;
namespace TerraFX.Interop.Windows
{
internal partial struct LRESULT : IComparable, IComparable<LRESULT>, IEquatable<LRESULT>, IFormattable
internal readonly partial struct LRESULT : IComparable, IComparable<LRESULT>, IEquatable<LRESULT>, IFormattable
{
public readonly nint Value;
+1 -1
ファイルの表示
@@ -4,7 +4,7 @@ using System;
namespace TerraFX.Interop.Windows
{
internal unsafe partial struct WPARAM : IComparable, IComparable<WPARAM>, IEquatable<WPARAM>, IFormattable
internal readonly unsafe partial struct WPARAM : IComparable, IComparable<WPARAM>, IEquatable<WPARAM>, IFormattable
{
public readonly nuint Value;
+2 -2
ファイルの表示
@@ -508,7 +508,7 @@ public sealed partial class BokehBlurEffect
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
[D2DRequiresScenePosition]
[AutoConstructor]
public partial struct Shader : ID2D1PixelShader
public readonly partial struct Shader : ID2D1PixelShader
{
public readonly int kernelLength;
@@ -557,7 +557,7 @@ public sealed partial class BokehBlurEffect
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
[D2DRequiresScenePosition]
[AutoConstructor]
public partial struct Shader : ID2D1PixelShader
public readonly partial struct Shader : ID2D1PixelShader
{
public readonly int kernelLength;
private readonly float z;
+2 -2
ファイルの表示
@@ -5,10 +5,10 @@ namespace ComputeSharp.D2D1.Tests.Effects;
[D2DRequiresScenePosition]
[D2DShaderProfile(D2D1ShaderProfile.PixelShader40)]
[AutoConstructor]
public partial struct PixelateEffect : ID2D1PixelShader
public readonly partial struct PixelateEffect : ID2D1PixelShader
{
[AutoConstructor]
public partial struct Constants
public readonly partial struct Constants
{
public readonly int inputWidth;
public readonly int inputHeight;
+1 -1
ファイルの表示
@@ -133,7 +133,7 @@ public partial class DeviceDisposalTests
[EmbeddedBytecode(DispatchAxis.X)]
[AutoConstructor]
private partial struct InitializeShader : IComputeShader
private readonly partial struct InitializeShader : IComputeShader
{
private readonly ReadWriteBuffer<float> buffer;
+1 -1
ファイルの表示
@@ -9,7 +9,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0-2.final" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0-4.final" />
</ItemGroup>
<ItemGroup>