Implement comparers for all model types
このコミットが含まれているのは:
1 親
5210c1ecd9
コミット
ed75dd4b5a
6ファイル変更
+223
-8
検索条件に一致するファイルはありません
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ComputeSharp.SourceGenerators.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Models;
|
||||
@@ -16,4 +18,56 @@ internal sealed record DispatchDataInfo(
|
||||
Type Type,
|
||||
ImmutableArray<FieldInfo> FieldInfos,
|
||||
int ResourceCount,
|
||||
int Root32BitConstantCount);
|
||||
int Root32BitConstantCount)
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="DispatchDataInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : IEqualityComparer<DispatchDataInfo>
|
||||
{
|
||||
/// <summary>
|
||||
/// The singleton <see cref="Comparer"/> instance.
|
||||
/// </summary>
|
||||
public static Comparer Default { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(DispatchDataInfo? x, DispatchDataInfo? 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
|
||||
HierarchyInfo.Comparer.Default.Equals(x.Hierarchy, y.Hierarchy) &&
|
||||
x.Type == y.Type &&
|
||||
x.FieldInfos.SequenceEqual(y.FieldInfos, FieldInfo.Comparer.Default) &&
|
||||
x.ResourceCount == y.ResourceCount &&
|
||||
x.Root32BitConstantCount == y.Root32BitConstantCount;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int GetHashCode(DispatchDataInfo obj)
|
||||
{
|
||||
HashCode hashCode = default;
|
||||
|
||||
hashCode.Add(HierarchyInfo.Comparer.Default.GetHashCode(obj.Hierarchy));
|
||||
hashCode.Add(obj.Type);
|
||||
hashCode.AddRange(obj.FieldInfos, FieldInfo.Comparer.Default);
|
||||
hashCode.Add(obj.ResourceCount);
|
||||
hashCode.Add(obj.Root32BitConstantCount);
|
||||
|
||||
return hashCode.ToHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
using System.Collections.Immutable;
|
||||
using ComputeSharp.SourceGenerators.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.Models;
|
||||
|
||||
@@ -39,4 +42,96 @@ internal abstract record FieldInfo
|
||||
int Rows,
|
||||
int Columns,
|
||||
ImmutableArray<int> Offsets) : FieldInfo;
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="FieldInfo"/>.
|
||||
/// </summary>
|
||||
public sealed class Comparer : IEqualityComparer<FieldInfo>
|
||||
{
|
||||
/// <summary>
|
||||
/// The singleton <see cref="Comparer"/> instance.
|
||||
/// </summary>
|
||||
public static Comparer Default { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Equals(FieldInfo? x, FieldInfo? 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;
|
||||
}
|
||||
|
||||
if (x is Resource resourceX && y is Resource resourceY)
|
||||
{
|
||||
return
|
||||
resourceX.FieldName == resourceY.FieldName &&
|
||||
resourceX.TypeName == resourceY.TypeName &&
|
||||
resourceX.Offset == resourceY.Offset;
|
||||
}
|
||||
else if (x is Primitive primitiveX && y is Primitive primitiveY)
|
||||
{
|
||||
return
|
||||
primitiveX.FieldPath.SequenceEqual(primitiveY.FieldPath) &&
|
||||
primitiveX.TypeName == primitiveY.TypeName &&
|
||||
primitiveX.Offset == primitiveY.Offset;
|
||||
}
|
||||
else if (x is NonLinearMatrix matrixX && y is NonLinearMatrix matrixY)
|
||||
{
|
||||
return
|
||||
matrixX.FieldPath.SequenceEqual(matrixY.FieldPath) &&
|
||||
matrixX.TypeName == matrixY.TypeName &&
|
||||
matrixX.ElementName == matrixY.ElementName &&
|
||||
matrixX.Rows == matrixY.Rows &&
|
||||
matrixY.Columns == matrixY.Columns &&
|
||||
matrixX.Offsets.SequenceEqual(matrixY.Offsets);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int GetHashCode(FieldInfo obj)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case Resource resource:
|
||||
return HashCode.Combine(resource.FieldName, resource.TypeName, resource.Offset);
|
||||
case Primitive primitive:
|
||||
{
|
||||
HashCode hashCode = default;
|
||||
|
||||
hashCode.AddRange(primitive.FieldPath);
|
||||
hashCode.Add(primitive.TypeName);
|
||||
hashCode.Add(primitive.Offset);
|
||||
|
||||
return hashCode.ToHashCode();
|
||||
}
|
||||
case NonLinearMatrix matrix:
|
||||
{
|
||||
HashCode hashCode = default;
|
||||
|
||||
hashCode.AddRange(matrix.FieldPath);
|
||||
hashCode.Add(matrix.TypeName);
|
||||
hashCode.Add(matrix.ElementName);
|
||||
hashCode.Add(matrix.Rows);
|
||||
hashCode.Add(matrix.Columns);
|
||||
hashCode.AddRange(matrix.Offsets);
|
||||
|
||||
return hashCode.ToHashCode();
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ internal sealed record HierarchyInfo(string FilenameHint, string Namespace, Immu
|
||||
return
|
||||
x.FilenameHint == y.FilenameHint &&
|
||||
x.Namespace == y.Namespace &&
|
||||
x.Names.AsSpan().SequenceEqual(y.Names.AsSpan());
|
||||
x.Names.SequenceEqual(y.Names);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -77,10 +77,10 @@ internal sealed record HlslSourceInfo(
|
||||
x.EntryPoint == y.EntryPoint &&
|
||||
x.ImplicitTextureType == y.ImplicitTextureType &&
|
||||
x.IsSamplerUsed == y.IsSamplerUsed &&
|
||||
x.DefinedTypes.AsSpan().SequenceEqual(y.DefinedTypes.AsSpan()) &&
|
||||
x.DefinedConstants.AsSpan().SequenceEqual(y.DefinedTypes.AsSpan()) &&
|
||||
x.MethodSignatures.AsSpan().SequenceEqual(y.MethodSignatures.AsSpan()) &&
|
||||
x.Delegates.AsSpan().SequenceEqual(y.Delegates.AsSpan());
|
||||
x.DefinedTypes.SequenceEqual(y.DefinedTypes) &&
|
||||
x.DefinedConstants.SequenceEqual(y.DefinedTypes) &&
|
||||
x.MethodSignatures.SequenceEqual(y.MethodSignatures) &&
|
||||
x.Delegates.SequenceEqual(y.Delegates);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする