From 358f378796e55611b2a1349bb4e671818a30cdd0 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 22 Oct 2023 13:21:09 +0200 Subject: [PATCH] Replace ToArray() with collection expressions --- build/Directory.Build.props | 2 +- .../SyntaxRewriters/ShaderSourceRewriter.cs | 4 ++-- .../Helpers/EquatableArray{T}.cs | 2 +- .../Helpers/ImmutableHashSetBuilder{T}.cs | 5 ++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/build/Directory.Build.props b/build/Directory.Build.props index 6ff78624..3d4fc91d 100644 --- a/build/Directory.Build.props +++ b/build/Directory.Build.props @@ -46,7 +46,7 @@ This is used eg. to replace Unsafe.SizeOf() calls with just sizeof(T). The warning is not necessary since in order to use these APIs the caller already has to be in an unsafe context. --> - $(NoWarn);CS8500;IDE0305;IDE0028;IDE0300;IDE0301;IDE0302 + $(NoWarn);CS8500;IDE0028;IDE0300;IDE0301;IDE0302 diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs index 3e41bb7f..6889951c 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs @@ -150,7 +150,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter BlockSyntax implicitBlock = Block(this.implicitVariables.Select(static v => LocalDeclarationStatement(v)).ToArray()); // Add the tracked implicit declarations (at the start of the body) - updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements(updatedNode.Body!.Statements.ToArray()); + updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements([.. updatedNode.Body!.Statements]); } return updatedNode; @@ -184,7 +184,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter { BlockSyntax implicitBlock = Block(this.implicitVariables.Select(static v => LocalDeclarationStatement(v)).ToArray()); - updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements(updatedNode.Body!.Statements.ToArray()); + updatedNode = updatedNode.WithBody(implicitBlock).AddBodyStatements([.. updatedNode.Body!.Statements]); } return updatedNode; diff --git a/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs b/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs index 7202a243..1f1088de 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs @@ -162,7 +162,7 @@ internal readonly struct EquatableArray(ImmutableArray array) : IEquatable /// The newly instantiated array. public T[] ToArray() { - return AsImmutableArray().ToArray(); + return [.. AsImmutableArray()]; } /// diff --git a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs index fe6a92a7..21209d6e 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/ImmutableHashSetBuilder{T}.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Linq; using System.Runtime.CompilerServices; namespace ComputeSharp.SourceGeneration.Helpers; @@ -64,7 +63,7 @@ internal struct ImmutableHashSetBuilder : IDisposable /// public readonly ImmutableArray ToImmutable() { - T[] array = this.set!.ToArray(); + T[] array = [.. this.set!]; return Unsafe.As>(ref array); } @@ -72,7 +71,7 @@ internal struct ImmutableHashSetBuilder : IDisposable /// public readonly T[] ToArray() { - return this.set!.ToArray(); + return [.. this.set!]; } ///