Skip to content

Commit

Permalink
perf: Remove foreach in ItemsControl.UpdateItems
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Sep 14, 2021
1 parent 17f2e4f commit b34954e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/ItemsControl/ItemsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,13 @@ protected virtual bool UpdateItems()

var results = ItemsPanelRoot.Children.UpdateWithResults(containers.OfType<UIElement>(), comparer: new ViewComparer());

foreach (var removed in results.Removed)
// This block is a manual enumeration to avoid the foreach pattern
// See https://github.com/dotnet/runtime/issues/56309 for details
var removedEnumerator = results.Removed.GetEnumerator();
while(removedEnumerator.MoveNext())
{
var removed = removedEnumerator.Current;

if (removed is DependencyObject removedObject)
{
CleanUpContainer(removedObject);
Expand Down

0 comments on commit b34954e

Please sign in to comment.