diff --git a/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs b/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs index 7c4c30ab..2c7e9730 100644 --- a/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs +++ b/src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs @@ -70,6 +70,15 @@ internal readonly struct EquatableArray : IEquatable>, IEnu get => AsImmutableArray().IsEmpty; } + /// + /// Gets the length of the current array. + /// + public int Length + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => AsImmutableArray().Length; + } + /// public bool Equals(EquatableArray array) { diff --git a/src/ComputeSharp.SourceGeneration/Models/DeferredDiagnosticInfo.cs b/src/ComputeSharp.SourceGeneration/Models/DeferredDiagnosticInfo.cs index 47d6c1b2..a88117ba 100644 --- a/src/ComputeSharp.SourceGeneration/Models/DeferredDiagnosticInfo.cs +++ b/src/ComputeSharp.SourceGeneration/Models/DeferredDiagnosticInfo.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; using Microsoft.CodeAnalysis; @@ -13,20 +10,8 @@ namespace ComputeSharp.SourceGeneration.Models; /// /// The wrapped instance. /// The diagnostic arguments. -internal sealed record DeferredDiagnosticInfo(DiagnosticDescriptor Descriptor, ImmutableArray Arguments) +internal sealed record DeferredDiagnosticInfo(DiagnosticDescriptor Descriptor, EquatableArray Arguments) { - /// - public bool Equals(DeferredDiagnosticInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - /// /// Creates a new instance with the specified parameters. /// @@ -37,25 +22,4 @@ internal sealed record DeferredDiagnosticInfo(DiagnosticDescriptor Descriptor, I { return new(descriptor, args.Select(static arg => arg.ToString()).ToImmutableArray()); } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, DeferredDiagnosticInfo obj) - { - hashCode.Add(obj.Descriptor); - hashCode.AddRange(obj.Arguments); - } - - /// - protected override bool AreEqual(DeferredDiagnosticInfo x, DeferredDiagnosticInfo y) - { - return - x.Descriptor.Equals(y.Descriptor) && - x.Arguments.SequenceEqual(y.Arguments); - } - } } \ No newline at end of file diff --git a/src/ComputeSharp.SourceGeneration/Models/DiagnosticInfo.cs b/src/ComputeSharp.SourceGeneration/Models/DiagnosticInfo.cs index 24937c14..e7009ff6 100644 --- a/src/ComputeSharp.SourceGeneration/Models/DiagnosticInfo.cs +++ b/src/ComputeSharp.SourceGeneration/Models/DiagnosticInfo.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; -using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Text; @@ -16,24 +13,8 @@ namespace ComputeSharp.SourceGeneration.Models; /// The tree to use as location for the diagnostic, if available. /// The span to use as location for the diagnostic. /// The diagnostic arguments. -internal sealed record DiagnosticInfo( - DiagnosticDescriptor Descriptor, - SyntaxTree? SyntaxTree, - TextSpan TextSpan, - ImmutableArray Arguments) +internal sealed record DiagnosticInfo(DiagnosticDescriptor Descriptor, SyntaxTree? SyntaxTree, TextSpan TextSpan, EquatableArray Arguments) { - /// - public bool Equals(DiagnosticInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - /// /// Creates a new instance with the state from this model. /// @@ -75,29 +56,4 @@ internal sealed record DiagnosticInfo( return new(descriptor, location.SourceTree, location.SourceSpan, args.Select(static arg => arg.ToString()).ToImmutableArray()); } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, DiagnosticInfo obj) - { - hashCode.Add(obj.Descriptor); - hashCode.Add(obj.SyntaxTree); - hashCode.Add(obj.TextSpan); - hashCode.AddRange(obj.Arguments); - } - - /// - protected override bool AreEqual(DiagnosticInfo x, DiagnosticInfo y) - { - return - x.Descriptor.Equals(y.Descriptor) && - x.SyntaxTree == y.SyntaxTree && - x.TextSpan.Equals(y.TextSpan) && - x.Arguments.SequenceEqual(y.Arguments); - } - } } \ No newline at end of file diff --git a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs index a9450d58..0a72429c 100644 --- a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs +++ b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; using Microsoft.CodeAnalysis; @@ -18,7 +15,7 @@ namespace ComputeSharp.SourceGeneration.Models; /// The fully qualified metadata name for the current type. /// Gets the namespace for the current type. /// Gets the sequence of type definitions containing the current type. -internal sealed partial record HierarchyInfo(string FilenameHint, string FullyQualifiedMetadataName, string Namespace, ImmutableArray Hierarchy) +internal sealed partial record HierarchyInfo(string FilenameHint, string FullyQualifiedMetadataName, string Namespace, EquatableArray Hierarchy) { /// /// Creates a new instance from a given . @@ -110,41 +107,4 @@ internal sealed partial record HierarchyInfo(string FilenameHint, string FullyQu .AddMembers(typeDeclarationSyntax)) .NormalizeWhitespace(eol: "\n"); } - - /// - public bool Equals(HierarchyInfo? obj) - { - return Comparer.Default.Equals(this, obj); - } - - /// - public override int GetHashCode() - { - return Comparer.Default.GetHashCode(this); - } - - /// - /// An implementation for . - /// - private sealed class Comparer : Comparer - { - /// - protected override void AddToHashCode(ref HashCode hashCode, HierarchyInfo obj) - { - hashCode.Add(obj.FilenameHint); - hashCode.Add(obj.FullyQualifiedMetadataName); - hashCode.Add(obj.Namespace); - hashCode.AddRange(obj.Hierarchy); - } - - /// - protected override bool AreEqual(HierarchyInfo x, HierarchyInfo y) - { - return - x.FilenameHint == y.FilenameHint && - x.FullyQualifiedMetadataName == y.FullyQualifiedMetadataName && - x.Namespace == y.Namespace && - x.Hierarchy.SequenceEqual(y.Hierarchy); - } - } } \ No newline at end of file