From 10fb1d20d1c4498ec232d91f2ffdc8781ebeae61 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 11 Oct 2018 18:38:04 +0900 Subject: [PATCH] Remove allocation of control point with every binarysearch --- .../Beatmaps/ControlPoints/ControlPointInfo.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index dad69321a5..2be7f4e16d 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -12,6 +12,11 @@ namespace osu.Game.Beatmaps.ControlPoints [Serializable] public class ControlPointInfo { + private readonly TimingControlPoint timingPointSearch = new TimingControlPoint(); + private readonly DifficultyControlPoint difficultyPointSearch = new DifficultyControlPoint(); + private readonly SampleControlPoint samplePointSearch = new SampleControlPoint(); + private readonly EffectControlPoint effectPointSearch = new EffectControlPoint(); + /// /// All timing points. /// @@ -41,28 +46,28 @@ namespace osu.Game.Beatmaps.ControlPoints /// /// The time to find the difficulty control point at. /// The difficulty control point. - public DifficultyControlPoint DifficultyPointAt(double time) => binarySearch(DifficultyPoints, time); + public DifficultyControlPoint DifficultyPointAt(double time) => binarySearch(DifficultyPoints, time, difficultyPointSearch); /// /// Finds the effect control point that is active at . /// /// The time to find the effect control point at. /// The effect control point. - public EffectControlPoint EffectPointAt(double time) => binarySearch(EffectPoints, time); + public EffectControlPoint EffectPointAt(double time) => binarySearch(EffectPoints, time, effectPointSearch); /// /// Finds the sound control point that is active at . /// /// The time to find the sound control point at. /// The sound control point. - public SampleControlPoint SamplePointAt(double time) => binarySearch(SamplePoints, time, SamplePoints.FirstOrDefault()); + public SampleControlPoint SamplePointAt(double time) => binarySearch(SamplePoints, time, samplePointSearch, SamplePoints.FirstOrDefault()); /// /// Finds the timing control point that is active at . /// /// The time to find the timing control point at. /// The timing control point. - public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, TimingPoints.FirstOrDefault()); + public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, timingPointSearch, TimingPoints.FirstOrDefault()); /// /// Finds the maximum BPM represented by any timing control point. @@ -92,7 +97,7 @@ namespace osu.Game.Beatmaps.ControlPoints /// The time to find the control point at. /// The control point to use when is before any control points. If null, a new control point will be constructed. /// The active control point at . - private T binarySearch(SortedList list, double time, T prePoint = null) + private T binarySearch(SortedList list, double time, T searchPoint, T prePoint = null) where T : ControlPoint, new() { if (list == null) @@ -104,7 +109,8 @@ namespace osu.Game.Beatmaps.ControlPoints if (time < list[0].Time) return prePoint ?? new T(); - int index = list.BinarySearch(new T { Time = time }); + searchPoint.Time = time; + int index = list.BinarySearch(searchPoint); // Check if we've found an exact match (t == time) if (index >= 0)