44using System ;
55using System . Collections . Generic ;
66using System . Diagnostics ;
7- using System . Runtime . CompilerServices ;
87using Microsoft . AspNetCore . Components . RenderTree ;
98
109namespace Microsoft . AspNetCore . Components . Rendering
@@ -27,7 +26,7 @@ public sealed class RenderTreeBuilder : IDisposable
2726 private readonly Stack < int > _openElementIndices = new Stack < int > ( ) ;
2827 private RenderTreeFrameType ? _lastNonAttributeFrameType ;
2928 private bool _hasSeenAddMultipleAttributes ;
30- private MultipleAttributesDictionary ? _seenAttributeNames ;
29+ private Dictionary < string , int > ? _seenAttributeNames ;
3130
3231 /// <summary>
3332 /// The reserved parameter name used for supplying child content.
@@ -707,21 +706,22 @@ internal void ProcessDuplicateAttributes(int first)
707706 }
708707
709708 // Now that we've found the last attribute, we can iterate backwards and process duplicates.
710- var seenAttributeNames = ( _seenAttributeNames ??= new MultipleAttributesDictionary ( ) ) ;
709+ var seenAttributeNames = ( _seenAttributeNames ??= new Dictionary < string , int > ( SimplifiedStringHashComparer . Instance ) ) ;
711710 for ( var i = last ; i >= first ; i -- )
712711 {
713712 ref var frame = ref buffer [ i ] ;
714713 Debug . Assert ( frame . FrameTypeField == RenderTreeFrameType . Attribute , $ "Frame type is { frame . FrameTypeField } at { i } ") ;
715714
716- if ( ! seenAttributeNames . TryAdd ( frame . AttributeNameField , i , out var index ) )
715+ if ( ! seenAttributeNames . TryAdd ( frame . AttributeNameField , i ) )
717716 {
717+ var index = seenAttributeNames [ frame . AttributeNameField ] ;
718718 if ( index < i )
719719 {
720720 // This attribute is overriding a "silent frame" where we didn't create a frame for an AddAttribute call.
721721 // This is the case for a null event handler, or bool false value.
722722 //
723723 // We need to update our tracking, in case the attribute appeared 3 or more times.
724- seenAttributeNames . Replace ( frame . AttributeNameField , i ) ;
724+ seenAttributeNames [ frame . AttributeNameField ] = i ;
725725 }
726726 else if ( index > i )
727727 {
@@ -778,8 +778,8 @@ internal void TrackAttributeName(string name)
778778 return ;
779779 }
780780
781- var seenAttributeNames = ( _seenAttributeNames ??= new MultipleAttributesDictionary ( ) ) ;
782- seenAttributeNames . TryAdd ( name , _entries . Count , out _ ) ; // See comment in ProcessAttributes for why this is OK.
781+ var seenAttributeNames = ( _seenAttributeNames ??= new Dictionary < string , int > ( SimplifiedStringHashComparer . Instance ) ) ;
782+ seenAttributeNames [ name ] = _entries . Count ; // See comment in ProcessAttributes for why this is OK.
783783 }
784784
785785 void IDisposable . Dispose ( )
0 commit comments