From 8402d7d476695a619d60636f175d883145ce1faa Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Tue, 30 Aug 2022 16:12:58 +0300 Subject: [PATCH] Improved Widget.RemoveChildren performance Modifying the list potentially several thousand times is really slow, so notify the child elements that they are being removed and then clear the list in one go. --- OpenRA.Game/Widgets/Widget.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 32a1f0ebcd..2f19e0a150 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -524,8 +524,10 @@ namespace OpenRA.Widgets public virtual void RemoveChildren() { - while (Children.Count > 0) - RemoveChild(Children[Children.Count - 1]); + foreach (var child in Children) + child?.Removed(); + + Children.Clear(); } public virtual void Hidden()