Streamline equality comparison of generation models
このコミットが含まれているのは:
1 親
6e247639ed
コミット
6b0c1161c8
19ファイル変更
+249
-607
検索条件に一致するファイルはありません
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.Models;
|
||||
@@ -15,49 +16,25 @@ internal sealed record DiagnosticInfo(DiagnosticDescriptor Descriptor, params ob
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="DiagnosticInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : IEqualityComparer<DiagnosticInfo>
|
||||
public sealed class Comparer : Comparer<DiagnosticInfo, Comparer>
|
||||
{
|
||||
/// <summary>
|
||||
/// The singleton <see cref="Comparer"/> instance.
|
||||
/// </summary>
|
||||
public static Comparer Default { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(DiagnosticInfo? x, DiagnosticInfo? y)
|
||||
protected override void AddToHashCode(ref HashCode hashCode, DiagnosticInfo obj)
|
||||
{
|
||||
if (x is null && y is null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (x is null || y is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(x, y))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return
|
||||
x.Descriptor.Equals(y.Descriptor) &&
|
||||
x.Args.SequenceEqual(y.Args);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int GetHashCode(DiagnosticInfo obj)
|
||||
{
|
||||
HashCode hashCode = default;
|
||||
|
||||
hashCode.Add(obj.Descriptor);
|
||||
|
||||
|
||||
foreach (object arg in obj.Args)
|
||||
{
|
||||
hashCode.Add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
return hashCode.ToHashCode();
|
||||
/// <inheritdoc/>
|
||||
protected override bool AreEqual(DiagnosticInfo x, DiagnosticInfo y)
|
||||
{
|
||||
return
|
||||
x.Descriptor.Equals(y.Descriptor) &&
|
||||
x.Args.SequenceEqual(y.Args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using static Microsoft.CodeAnalysis.SymbolDisplayTypeQualificationStyle;
|
||||
|
||||
@@ -42,49 +43,25 @@ internal sealed record HierarchyInfo(string FilenameHint, string MetadataName, s
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="HierarchyInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : IEqualityComparer<HierarchyInfo>
|
||||
public sealed class Comparer : Comparer<HierarchyInfo, Comparer>
|
||||
{
|
||||
/// <summary>
|
||||
/// The singleton <see cref="Comparer"/> instance.
|
||||
/// </summary>
|
||||
public static Comparer Default { get; } = new();
|
||||
/// <inheritdoc/>
|
||||
protected override void AddToHashCode(ref HashCode hashCode, HierarchyInfo obj)
|
||||
{
|
||||
hashCode.Add(obj.FilenameHint);
|
||||
hashCode.Add(obj.MetadataName);
|
||||
hashCode.Add(obj.Namespace);
|
||||
hashCode.AddRange(obj.Names);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(HierarchyInfo? x, HierarchyInfo? y)
|
||||
protected override bool AreEqual(HierarchyInfo x, HierarchyInfo y)
|
||||
{
|
||||
if (x is null && y is null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (x is null || y is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(x, y))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return
|
||||
x.FilenameHint == y.FilenameHint &&
|
||||
x.MetadataName == y.MetadataName &&
|
||||
x.Namespace == y.Namespace &&
|
||||
x.Names.SequenceEqual(y.Names);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int GetHashCode(HierarchyInfo obj)
|
||||
{
|
||||
HashCode hashCode = default;
|
||||
|
||||
hashCode.Add(obj.FilenameHint);
|
||||
hashCode.Add(obj.MetadataName);
|
||||
hashCode.Add(obj.Namespace);
|
||||
hashCode.AddRange(obj.Names);
|
||||
|
||||
return hashCode.ToHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする