From 1125075b374ea717111998ab4f0f20a357baf98d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 10 Oct 2018 13:02:27 +0900 Subject: [PATCH 1/4] Use list with post-sort for nested hitobjects --- osu.Game/Rulesets/Objects/HitObject.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index beb9620f78..80a3677b12 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -58,7 +58,7 @@ namespace osu.Game.Rulesets.Objects /// public HitWindows HitWindows { get; set; } - private readonly Lazy> nestedHitObjects = new Lazy>(() => new SortedList((h1, h2) => h1.StartTime.CompareTo(h2.StartTime))); + private readonly Lazy> nestedHitObjects = new Lazy>(() => new List()); [JsonIgnore] public IReadOnlyList NestedHitObjects => nestedHitObjects.Value; @@ -79,6 +79,8 @@ namespace osu.Game.Rulesets.Objects if (nestedHitObjects.IsValueCreated) { + nestedHitObjects.Value.Sort((h1, h2) => h1.StartTime.CompareTo(h2.StartTime)); + nestedHitObjects.Value.ForEach(h => { h.HitWindows = HitWindows; From 417ebaeb857a50f65f484ca5c6d424539046f3b0 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 10 Oct 2018 13:03:18 +0900 Subject: [PATCH 2/4] Reduce hitobject size by removing lazy --- osu.Game/Rulesets/Objects/HitObject.cs | 27 ++++++++++---------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index 80a3677b12..e52d6b416f 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -1,11 +1,8 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.Collections.Generic; using Newtonsoft.Json; -using osu.Framework.Extensions.IEnumerableExtensions; -using osu.Framework.Lists; using osu.Game.Audio; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; @@ -58,10 +55,10 @@ namespace osu.Game.Rulesets.Objects /// public HitWindows HitWindows { get; set; } - private readonly Lazy> nestedHitObjects = new Lazy>(() => new List()); + private readonly List nestedHitObjects = new List(); [JsonIgnore] - public IReadOnlyList NestedHitObjects => nestedHitObjects.Value; + public IReadOnlyList NestedHitObjects => nestedHitObjects; /// /// Applies default values to this HitObject. @@ -72,21 +69,17 @@ namespace osu.Game.Rulesets.Objects { ApplyDefaultsToSelf(controlPointInfo, difficulty); - if (nestedHitObjects.IsValueCreated) - nestedHitObjects.Value.Clear(); + nestedHitObjects.Clear(); CreateNestedHitObjects(); - if (nestedHitObjects.IsValueCreated) - { - nestedHitObjects.Value.Sort((h1, h2) => h1.StartTime.CompareTo(h2.StartTime)); + nestedHitObjects.Sort((h1, h2) => h1.StartTime.CompareTo(h2.StartTime)); - nestedHitObjects.Value.ForEach(h => - { - h.HitWindows = HitWindows; - h.ApplyDefaults(controlPointInfo, difficulty); - }); - } + nestedHitObjects.ForEach(h => + { + h.HitWindows = HitWindows; + h.ApplyDefaults(controlPointInfo, difficulty); + }); } protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) @@ -106,7 +99,7 @@ namespace osu.Game.Rulesets.Objects { } - protected void AddNested(HitObject hitObject) => nestedHitObjects.Value.Add(hitObject); + protected void AddNested(HitObject hitObject) => nestedHitObjects.Add(hitObject); /// /// Creates the that represents the scoring information for this . From f53bb81723372ab9bb462b616ecdb89e73058b4c Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 10 Oct 2018 14:58:29 +0900 Subject: [PATCH 3/4] Remove unnecessary lambda allocation --- osu.Game/Rulesets/Objects/HitObject.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index e52d6b416f..67a3db7a00 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -75,11 +75,11 @@ namespace osu.Game.Rulesets.Objects nestedHitObjects.Sort((h1, h2) => h1.StartTime.CompareTo(h2.StartTime)); - nestedHitObjects.ForEach(h => + foreach (var h in nestedHitObjects) { h.HitWindows = HitWindows; h.ApplyDefaults(controlPointInfo, difficulty); - }); + } } protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) From d282d16e1cb31595e4e140d8a49179a182ee8c98 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 11 Oct 2018 20:49:12 +0900 Subject: [PATCH 4/4] Use SortedList again --- osu.Game/Rulesets/Objects/HitObject.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index 67a3db7a00..f5613e927f 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Newtonsoft.Json; +using osu.Framework.Lists; using osu.Game.Audio; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; @@ -55,7 +56,7 @@ namespace osu.Game.Rulesets.Objects /// public HitWindows HitWindows { get; set; } - private readonly List nestedHitObjects = new List(); + private readonly SortedList nestedHitObjects = new SortedList(compareObjects); [JsonIgnore] public IReadOnlyList NestedHitObjects => nestedHitObjects; @@ -73,8 +74,6 @@ namespace osu.Game.Rulesets.Objects CreateNestedHitObjects(); - nestedHitObjects.Sort((h1, h2) => h1.StartTime.CompareTo(h2.StartTime)); - foreach (var h in nestedHitObjects) { h.HitWindows = HitWindows; @@ -115,5 +114,7 @@ namespace osu.Game.Rulesets.Objects /// /// protected virtual HitWindows CreateHitWindows() => new HitWindows(); + + private static int compareObjects(HitObject first, HitObject second) => first.StartTime.CompareTo(second.StartTime); } }