1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 02:17:46 +08:00

Merge pull request #26940 from EVAST9919/playfield-mods-alloc

Reduce allocation overhead in `Playfield`
This commit is contained in:
Dan Balasescu 2024-02-02 15:45:46 +09:00 committed by GitHub
commit 108375975d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -247,10 +247,14 @@ namespace osu.Game.Rulesets.UI
nestedPlayfields.Add(otherPlayfield); nestedPlayfields.Add(otherPlayfield);
} }
private Mod[] mods;
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
mods = Mods?.ToArray();
// in the case a consumer forgets to add the HitObjectContainer, we will add it here. // in the case a consumer forgets to add the HitObjectContainer, we will add it here.
if (HitObjectContainer.Parent == null) if (HitObjectContainer.Parent == null)
AddInternal(HitObjectContainer); AddInternal(HitObjectContainer);
@ -260,9 +264,9 @@ namespace osu.Game.Rulesets.UI
{ {
base.Update(); 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) if (mod is IUpdatableByPlayfield updatable)
updatable.Update(this); 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. // 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. // 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<IApplicableToDrawableHitObject>()) foreach (Mod mod in mods)
m.ApplyToDrawableHitObject(dho); {
if (mod is IApplicableToDrawableHitObject applicable)
applicable.ApplyToDrawableHitObject(dho);
}
} }
} }