1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 22:03:21 +08:00

freeIfInUse -> free, and add comments

This commit is contained in:
ekrctb 2021-04-26 12:04:59 +09:00
parent e6474e6ff7
commit 20e3cadd30

View File

@ -50,6 +50,7 @@ namespace osu.Game.Rulesets.Objects.Pooling
{ {
base.LoadAsyncComplete(); base.LoadAsyncComplete();
// Apply the initial entry given in the constructor.
if (Entry != null && !HasEntryApplied) if (Entry != null && !HasEntryApplied)
Apply(Entry); Apply(Entry);
} }
@ -60,7 +61,8 @@ namespace osu.Game.Rulesets.Objects.Pooling
/// </summary> /// </summary>
public void Apply(TEntry entry) public void Apply(TEntry entry)
{ {
freeIfInUse(); if (HasEntryApplied)
free();
setLifetime(entry.LifetimeStart, entry.LifetimeEnd); setLifetime(entry.LifetimeStart, entry.LifetimeEnd);
Entry = entry; Entry = entry;
@ -74,8 +76,9 @@ namespace osu.Game.Rulesets.Objects.Pooling
{ {
base.FreeAfterUse(); base.FreeAfterUse();
if (IsInPool) // We preserve the existing entry in case we want to move a non-pooled drawable between different parent drawables.
freeIfInUse(); if (HasEntryApplied && IsInPool)
free();
} }
/// <summary> /// <summary>
@ -104,11 +107,9 @@ namespace osu.Game.Rulesets.Objects.Pooling
} }
} }
private void freeIfInUse() private void free()
{ {
if (!HasEntryApplied) return; Debug.Assert(Entry != null && HasEntryApplied);
Debug.Assert(Entry != null);
OnFree(Entry); OnFree(Entry);