From 28caf0d74c09ff8db4f006c6bc1e2c82db5658d5 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Tue, 29 Dec 2020 03:58:09 +0100 Subject: [PATCH] Reduce allocations --- .../Components/Animations/AnimationPlayerComponent.cs | 10 ++++++++++ Robust.Client/UserInterface/Control.cs | 2 +- .../UserInterface/CustomControls/DebugInputPanel.cs | 5 +++++ .../UserInterface/CustomControls/DebugNetPanel.cs | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Robust.Client/GameObjects/Components/Animations/AnimationPlayerComponent.cs b/Robust.Client/GameObjects/Components/Animations/AnimationPlayerComponent.cs index 1115fa5ec8..dc50afe178 100644 --- a/Robust.Client/GameObjects/Components/Animations/AnimationPlayerComponent.cs +++ b/Robust.Client/GameObjects/Components/Animations/AnimationPlayerComponent.cs @@ -48,11 +48,21 @@ namespace Robust.Client.GameObjects.Components.Animations return; } + List? toRemove = null; // TODO: Get rid of this ToArray() allocation. foreach (var (key, playback) in _playingAnimations.ToArray()) { var keep = UpdatePlayback(Owner, playback, frameTime); if (!keep) + { + toRemove ??= new List(); + toRemove.Add(key); + } + } + + if (toRemove != null) + { + foreach (var key in toRemove) { _playingAnimations.Remove(key); AnimationCompleted?.Invoke(key); diff --git a/Robust.Client/UserInterface/Control.cs b/Robust.Client/UserInterface/Control.cs index 1efdf46953..ffcd98d72d 100644 --- a/Robust.Client/UserInterface/Control.cs +++ b/Robust.Client/UserInterface/Control.cs @@ -521,7 +521,7 @@ namespace Robust.Client.UserInterface { DebugTools.Assert(!Disposed, "Control has been disposed."); - foreach (var child in Children.ToList()) + foreach (var child in Children.ToArray()) { RemoveChild(child); } diff --git a/Robust.Client/UserInterface/CustomControls/DebugInputPanel.cs b/Robust.Client/UserInterface/CustomControls/DebugInputPanel.cs index 3dc0f218b8..06f9771d2d 100644 --- a/Robust.Client/UserInterface/CustomControls/DebugInputPanel.cs +++ b/Robust.Client/UserInterface/CustomControls/DebugInputPanel.cs @@ -31,6 +31,11 @@ namespace Robust.Client.UserInterface.CustomControls { base.FrameUpdate(args); + if (!VisibleInTree) + { + return; + } + _label.Text = string.Join("\n", _inputManager.DownKeyFunctions); } } diff --git a/Robust.Client/UserInterface/CustomControls/DebugNetPanel.cs b/Robust.Client/UserInterface/CustomControls/DebugNetPanel.cs index 12805d8c94..ac945c78c1 100644 --- a/Robust.Client/UserInterface/CustomControls/DebugNetPanel.cs +++ b/Robust.Client/UserInterface/CustomControls/DebugNetPanel.cs @@ -64,6 +64,11 @@ namespace Robust.Client.UserInterface.CustomControls return; } + if (!VisibleInTree) + { + return; + } + if (!NetManager.IsConnected) { contents.Text = "Not connected to server.";