From 53c5483eba108acb4c8782764ae4840d414428dd Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Fri, 2 Feb 2024 04:53:48 +0300 Subject: [PATCH] Reduce allocation in Playfield --- osu.Game/Rulesets/UI/Playfield.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/osu.Game/Rulesets/UI/Playfield.cs b/osu.Game/Rulesets/UI/Playfield.cs index e9c35555c8..90a2f63faa 100644 --- a/osu.Game/Rulesets/UI/Playfield.cs +++ b/osu.Game/Rulesets/UI/Playfield.cs @@ -247,10 +247,14 @@ namespace osu.Game.Rulesets.UI nestedPlayfields.Add(otherPlayfield); } + private Mod[] mods; + protected override void LoadComplete() { base.LoadComplete(); + mods = Mods?.ToArray(); + // in the case a consumer forgets to add the HitObjectContainer, we will add it here. if (HitObjectContainer.Parent == null) AddInternal(HitObjectContainer); @@ -260,9 +264,9 @@ namespace osu.Game.Rulesets.UI { base.Update(); - if (!IsNested && Mods != null) + if (!IsNested && mods != null) { - foreach (var mod in Mods) + foreach (Mod mod in mods) { if (mod is IUpdatableByPlayfield updatable) updatable.Update(this); @@ -403,10 +407,13 @@ namespace osu.Game.Rulesets.UI // If this is the first time this DHO is being used, then apply the DHO mods. // This is done before Apply() so that the state is updated once when the hitobject is applied. - if (Mods != null) + if (mods != null) { - foreach (var m in Mods.OfType()) - m.ApplyToDrawableHitObject(dho); + foreach (Mod mod in mods) + { + if (mod is IApplicableToDrawableHitObject applicable) + applicable.ApplyToDrawableHitObject(dho); + } } }