1- // Licensed to the .NET Foundation under one or more agreements.
1+ // Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System ;
@@ -76,6 +76,9 @@ static TagHelperCollection BuildCollection(ReadOnlySpan<TagHelperDescriptor> spa
7676 [ OverloadResolutionPriority ( 1 ) ]
7777 public static TagHelperCollection Create ( params ImmutableArray < TagHelperDescriptor > array )
7878 {
79+ // Note: We intentionally do *not* delegate to the Create(ReadOnlySpan<TagHelperDescriptor>)
80+ // overload, which must copy all of the elements from the span that's passed in.
81+ // We can use the underlying memory of the ImmutableArray directly.
7982 var segment = array . AsMemory ( ) ;
8083
8184 return segment . Span switch
@@ -119,7 +122,11 @@ public static TagHelperCollection Create(IEnumerable<TagHelperDescriptor> source
119122 {
120123 if ( source . TryGetCount ( out var count ) )
121124 {
122- // Copy the IEnumerable to an immutable array and delegate to the other Create method.
125+ // Copy the IEnumerable to an immutable array and delegate to the
126+ // Create(ImmutableArray<TagHelperDescriptor>) method.
127+
128+ // Note: We intentionally do *not* delegate to the Create(ReadOnlySpan<TagHelperDescriptor>)
129+ // overload, which must copy all of the elements from the span that's passed in.
123130 var array = new TagHelperDescriptor [ count ] ;
124131 source . CopyTo ( array ) ;
125132
@@ -129,8 +136,8 @@ public static TagHelperCollection Create(IEnumerable<TagHelperDescriptor> source
129136 // Fallback for an arbitrary IEnumerable with no count.
130137
131138 // Copy the IEnumerable to a MemoryBuilder and delegate to the other Create method.
132- // Note that we can pass a span below because Create(ReadOnlySpan<TagHelperDescriptor>)
133- // copies the elements into a new array.
139+ // Note that we can pass a span to the underlying pooled array below because
140+ // Create(ReadOnlySpan<TagHelperDescriptor>) copies the elements into a new array.
134141 using var builder = new MemoryBuilder < TagHelperDescriptor > ( clearArray : true ) ;
135142
136143 foreach ( var item in source )
0 commit comments