From cabecd5e4513116e1d62ef77926685deefa7c074 Mon Sep 17 00:00:00 2001 From: Stuart Turner Date: Sat, 6 Jan 2024 14:38:36 -0600 Subject: [PATCH] Fix Incorrect TransformBehaviors cacheability --- src/Immediate.Handlers/EquatableReadOnlyList.cs | 3 +-- .../Generators/ImmediateHandlersGenerator.cs | 15 ++++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Immediate.Handlers/EquatableReadOnlyList.cs b/src/Immediate.Handlers/EquatableReadOnlyList.cs index 5d34a302..7011f779 100644 --- a/src/Immediate.Handlers/EquatableReadOnlyList.cs +++ b/src/Immediate.Handlers/EquatableReadOnlyList.cs @@ -5,7 +5,7 @@ namespace Immediate.Handlers; public static class EquatableReadOnlyList { public static EquatableReadOnlyList ToEquatableReadOnlyList(this IEnumerable enumerable) - where T : IEquatable => new(enumerable.ToArray()); + => new(enumerable.ToArray()); } /// @@ -14,7 +14,6 @@ public static EquatableReadOnlyList ToEquatableReadOnlyList(this IEnumerab public readonly struct EquatableReadOnlyList( IReadOnlyList collection ) : IEquatable>, IReadOnlyList - where T : IEquatable { public bool Equals(EquatableReadOnlyList other) => this.SequenceEqual(other); diff --git a/src/Immediate.Handlers/Generators/ImmediateHandlersGenerator.cs b/src/Immediate.Handlers/Generators/ImmediateHandlersGenerator.cs index d115a1c9..134a60b1 100644 --- a/src/Immediate.Handlers/Generators/ImmediateHandlersGenerator.cs +++ b/src/Immediate.Handlers/Generators/ImmediateHandlersGenerator.cs @@ -116,7 +116,7 @@ private static RenderMode ParseRenderMode(AttributeData attr) } } - private static ImmutableArray TransformBehaviors( + private static EquatableReadOnlyList TransformBehaviors( GeneratorAttributeSyntaxContext context, CancellationToken cancellationToken ) @@ -129,7 +129,7 @@ CancellationToken cancellationToken var attr = context.Attributes[0]; if (attr.ConstructorArguments.Length != 1) - return ImmutableArray.Empty; + return []; var ca = attr.ConstructorArguments[0]; var arrayTypeSymbol = compilation.CreateArrayTypeSymbol( @@ -139,17 +139,17 @@ CancellationToken cancellationToken arrayTypeSymbol )) { - return ImmutableArray.Empty; + return []; } cancellationToken.ThrowIfCancellationRequested(); var behaviorType = typeof(Behavior<,>); var behaviorTypeSymbol = compilation.GetTypeByMetadataName(behaviorType.FullName); if (behaviorTypeSymbol is null) - return ImmutableArray.Empty; + return []; cancellationToken.ThrowIfCancellationRequested(); - var behaviors = ca.Values + return ca.Values .Select(v => { cancellationToken.ThrowIfCancellationRequested(); @@ -190,10 +190,7 @@ CancellationToken cancellationToken }; } }) - .ToArray(); - - cancellationToken.ThrowIfCancellationRequested(); - return ImmutableArray.Create(behaviors); + .ToEquatableReadOnlyList(); } private struct ConstraintInfo