Skip to content

Commit 986d922

Browse files
committed
perf(android): Don't sort Canvas children below 2
1 parent c410a4a commit 986d922

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/Uno.UI/UI/Xaml/Controls/Canvas/Canvas.Android.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,28 @@ partial void InitializePartial()
2121

2222
partial void MeasureOverridePartial()
2323
{
24-
if (_drawOrders?.Length != Children.Count)
24+
// Sorting is only needed when Children count is above 1
25+
if (Children.Count > 1)
2526
{
26-
_drawOrders = new int[Children.Count];
27-
}
27+
if (_drawOrders?.Length != Children.Count)
28+
{
29+
_drawOrders = new int[Children.Count];
30+
}
2831

29-
var sorted = Children
30-
.Select((view, childrenIndex) => (view, childrenIndex))
31-
.OrderBy(tpl => tpl.view is DependencyObject obj ? Canvas.GetZIndex(obj) : 0); // Note: this has to be a stable sort
32+
var sorted = Children
33+
.Select((view, childrenIndex) => (view, childrenIndex))
34+
.OrderBy(tpl => tpl.view is DependencyObject obj ? Canvas.GetZIndex(obj) : 0); // Note: this has to be a stable sort
3235

33-
var drawOrder = 0;
34-
foreach (var tpl in sorted)
36+
var drawOrder = 0;
37+
foreach (var tpl in sorted)
38+
{
39+
_drawOrders[tpl.childrenIndex] = drawOrder;
40+
drawOrder++;
41+
}
42+
}
43+
else
3544
{
36-
_drawOrders[tpl.childrenIndex] = drawOrder;
37-
drawOrder++;
45+
_drawOrders = null;
3846
}
3947
}
4048

0 commit comments

Comments
 (0)