|
4 | 4 | using System; |
5 | 5 | using System.Collections.Generic; |
6 | 6 | using System.Diagnostics; |
7 | | -using System.Runtime.CompilerServices; |
8 | 7 | using Microsoft.AspNetCore.Components.RenderTree; |
9 | 8 |
|
10 | 9 | namespace Microsoft.AspNetCore.Components.Rendering |
@@ -707,41 +706,40 @@ internal void ProcessDuplicateAttributes(int first) |
707 | 706 | } |
708 | 707 |
|
709 | 708 | // Now that we've found the last attribute, we can iterate backwards and process duplicates. |
710 | | - var seenAttributeNames = (_seenAttributeNames ??= new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)); |
| 709 | + var seenAttributeNames = (_seenAttributeNames ??= new Dictionary<string, int>(SimplifiedStringHashComparer.Instance)); |
711 | 710 | for (var i = last; i >= first; i--) |
712 | 711 | { |
713 | 712 | ref var frame = ref buffer[i]; |
714 | 713 | Debug.Assert(frame.FrameTypeField == RenderTreeFrameType.Attribute, $"Frame type is {frame.FrameTypeField} at {i}"); |
715 | 714 |
|
716 | | - if (!seenAttributeNames.TryGetValue(frame.AttributeNameField, out var index)) |
| 715 | + if (!seenAttributeNames.TryAdd(frame.AttributeNameField, i)) |
717 | 716 | { |
718 | | - // This is the first time seeing this attribute name. Add to the dictionary and move on. |
719 | | - seenAttributeNames.Add(frame.AttributeNameField, i); |
720 | | - } |
721 | | - else if (index < i) |
722 | | - { |
723 | | - // This attribute is overriding a "silent frame" where we didn't create a frame for an AddAttribute call. |
724 | | - // This is the case for a null event handler, or bool false value. |
725 | | - // |
726 | | - // We need to update our tracking, in case the attribute appeared 3 or more times. |
727 | | - seenAttributeNames[frame.AttributeNameField] = i; |
728 | | - } |
729 | | - else if (index > i) |
730 | | - { |
731 | | - // This attribute has been overridden. For now, blank out its name to *mark* it. We'll do a pass |
732 | | - // later to wipe it out. |
733 | | - frame = default; |
734 | | - } |
735 | | - else |
736 | | - { |
737 | | - // OK so index == i. How is that possible? Well it's possible for a "silent frame" immediately |
738 | | - // followed by setting the same attribute. Think of it this way, when we create a "silent frame" |
739 | | - // we have to track that attribute name with *some* index. |
740 | | - // |
741 | | - // The only index value we can safely use is _entries.Count (next available). This is fine because |
742 | | - // we never use these indexes to look stuff up, only for comparison. |
743 | | - // |
744 | | - // That gets you here, and there's no action to take. |
| 717 | + var index = seenAttributeNames[frame.AttributeNameField]; |
| 718 | + if (index < i) |
| 719 | + { |
| 720 | + // This attribute is overriding a "silent frame" where we didn't create a frame for an AddAttribute call. |
| 721 | + // This is the case for a null event handler, or bool false value. |
| 722 | + // |
| 723 | + // We need to update our tracking, in case the attribute appeared 3 or more times. |
| 724 | + seenAttributeNames[frame.AttributeNameField] = i; |
| 725 | + } |
| 726 | + else if (index > i) |
| 727 | + { |
| 728 | + // This attribute has been overridden. For now, blank out its name to *mark* it. We'll do a pass |
| 729 | + // later to wipe it out. |
| 730 | + frame = default; |
| 731 | + } |
| 732 | + else |
| 733 | + { |
| 734 | + // OK so index == i. How is that possible? Well it's possible for a "silent frame" immediately |
| 735 | + // followed by setting the same attribute. Think of it this way, when we create a "silent frame" |
| 736 | + // we have to track that attribute name with *some* index. |
| 737 | + // |
| 738 | + // The only index value we can safely use is _entries.Count (next available). This is fine because |
| 739 | + // we never use these indexes to look stuff up, only for comparison. |
| 740 | + // |
| 741 | + // That gets you here, and there's no action to take. |
| 742 | + } |
745 | 743 | } |
746 | 744 | } |
747 | 745 |
|
@@ -780,7 +778,7 @@ internal void TrackAttributeName(string name) |
780 | 778 | return; |
781 | 779 | } |
782 | 780 |
|
783 | | - var seenAttributeNames = (_seenAttributeNames ??= new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase)); |
| 781 | + var seenAttributeNames = (_seenAttributeNames ??= new Dictionary<string, int>(SimplifiedStringHashComparer.Instance)); |
784 | 782 | seenAttributeNames[name] = _entries.Count; // See comment in ProcessAttributes for why this is OK. |
785 | 783 | } |
786 | 784 |
|
|
0 commit comments