Skip to content

Commit

Permalink
Fix Incorrect TransformBehaviors cacheability
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin committed Jan 6, 2024
1 parent 1aea8c0 commit cabecd5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/Immediate.Handlers/EquatableReadOnlyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Immediate.Handlers;
public static class EquatableReadOnlyList
{
public static EquatableReadOnlyList<T> ToEquatableReadOnlyList<T>(this IEnumerable<T> enumerable)
where T : IEquatable<T> => new(enumerable.ToArray());
=> new(enumerable.ToArray());
}

/// <summary>
Expand All @@ -14,7 +14,6 @@ public static EquatableReadOnlyList<T> ToEquatableReadOnlyList<T>(this IEnumerab
public readonly struct EquatableReadOnlyList<T>(
IReadOnlyList<T> collection
) : IEquatable<EquatableReadOnlyList<T>>, IReadOnlyList<T>
where T : IEquatable<T>
{
public bool Equals(EquatableReadOnlyList<T> other)
=> this.SequenceEqual(other);
Expand Down
15 changes: 6 additions & 9 deletions src/Immediate.Handlers/Generators/ImmediateHandlersGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private static RenderMode ParseRenderMode(AttributeData attr)
}
}

private static ImmutableArray<Behavior?> TransformBehaviors(
private static EquatableReadOnlyList<Behavior?> TransformBehaviors(
GeneratorAttributeSyntaxContext context,
CancellationToken cancellationToken
)
Expand All @@ -129,7 +129,7 @@ CancellationToken cancellationToken

var attr = context.Attributes[0];
if (attr.ConstructorArguments.Length != 1)
return ImmutableArray<Behavior?>.Empty;
return [];

var ca = attr.ConstructorArguments[0];
var arrayTypeSymbol = compilation.CreateArrayTypeSymbol(
Expand All @@ -139,17 +139,17 @@ CancellationToken cancellationToken
arrayTypeSymbol
))
{
return ImmutableArray<Behavior?>.Empty;
return [];
}

cancellationToken.ThrowIfCancellationRequested();
var behaviorType = typeof(Behavior<,>);
var behaviorTypeSymbol = compilation.GetTypeByMetadataName(behaviorType.FullName);
if (behaviorTypeSymbol is null)
return ImmutableArray<Behavior?>.Empty;
return [];

cancellationToken.ThrowIfCancellationRequested();
var behaviors = ca.Values
return ca.Values
.Select(v =>
{
cancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -190,10 +190,7 @@ CancellationToken cancellationToken
};
}
})
.ToArray();

cancellationToken.ThrowIfCancellationRequested();
return ImmutableArray.Create(behaviors);
.ToEquatableReadOnlyList();
}

private struct ConstraintInfo
Expand Down

0 comments on commit cabecd5

Please sign in to comment.