From 43b1176f39bb70b085ea939bd902218047fa7051 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Fri, 14 Apr 2023 15:19:55 -0700 Subject: [PATCH] Convert to ImmutableArray to avoid extra LINQ evaluation --- .../src/DefaultTagHelperDescriptorFactory.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor/src/DefaultTagHelperDescriptorFactory.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor/src/DefaultTagHelperDescriptorFactory.cs index 4df495a374..fa5d160e98 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor/src/DefaultTagHelperDescriptorFactory.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor/src/DefaultTagHelperDescriptorFactory.cs @@ -64,9 +64,17 @@ internal class DefaultTagHelperDescriptorFactory private static void AddTagMatchingRules(INamedTypeSymbol type, TagHelperDescriptorBuilder descriptorBuilder) { - var targetElementAttributes = type - .GetAttributes() - .Where(static attribute => attribute.AttributeClass.HasFullName(TagHelperTypes.HtmlTargetElementAttribute)); + using var builder = new PooledArrayBuilder(); + + foreach (var attribute in type.GetAttributes()) + { + if (attribute.AttributeClass.HasFullName(TagHelperTypes.HtmlTargetElementAttribute)) + { + builder.Add(attribute); + } + } + + var targetElementAttributes = builder.ToImmutable(); // If there isn't an attribute specifying the tag name derive it from the name if (!targetElementAttributes.Any())