Skip to content

Commit

Permalink
[windows] less interops in calling get_Children (#21792)
Browse files Browse the repository at this point in the history
The PR trivially attempts to decrease the number of interops, using a local variable.

Contributes to #21787
  • Loading branch information
MartyIX committed Apr 19, 2024
1 parent ebd35ca commit 1d635bb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Core/src/Handlers/Layout/LayoutHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ public override void SetVirtualView(IView view)

PlatformView.CrossPlatformLayout = VirtualView;

PlatformView.Children.Clear();
var children = PlatformView.Children;
children.Clear();

foreach (var child in VirtualView.OrderByZIndex())
{
PlatformView.Children.Add(child.ToPlatform(MauiContext));
children.Add(child.ToPlatform(MauiContext));
}
}

Expand Down Expand Up @@ -108,7 +109,8 @@ void EnsureZIndexOrder(IView child)
return;
}

var currentIndex = PlatformView.Children.IndexOf(child.ToPlatform(MauiContext!));
var children = PlatformView.Children;
var currentIndex = children.IndexOf(child.ToPlatform(MauiContext!));

if (currentIndex == -1)
{
Expand All @@ -119,7 +121,7 @@ void EnsureZIndexOrder(IView child)

if (currentIndex != targetIndex)
{
PlatformView.Children.Move((uint)currentIndex, (uint)targetIndex);
children.Move((uint)currentIndex, (uint)targetIndex);
}
}

Expand Down

0 comments on commit 1d635bb

Please sign in to comment.