Skip to content

Commit 81ddc95

Browse files
authored
Stop boxing WeakReferenceListEnumerator in PresentationSource use (#6502)
PresentationSource.CriticalCurrentSources is internal and is only ever foreach'd by consumers. It's strongly-typed to return IEnumerable, but the actual WeakReferenceList it returns has a struct-based enumerator, which means each foreach boxes that enumerator. By changing CriticalCurrentSources to return `WeakReferenceList` rather than `IEnumerable`, those foreach's can bind directly to the struct, with all the benefits that brings.
1 parent b518cfb commit 81ddc95

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/PresentationSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,11 @@ internal static bool UnderSamePresentationSource(params DependencyObject[] visua
661661
/// over a ReadOnly SnapShot of the List of sources. The Enumerator
662662
/// skips over the any dead weak references in the list.
663663
/// </summary>
664-
internal static IEnumerable CriticalCurrentSources
664+
internal static WeakReferenceList CriticalCurrentSources
665665
{
666666
get
667667
{
668-
return (IEnumerable)_sources;
668+
return _sources;
669669
}
670670
}
671671

0 commit comments

Comments
 (0)