diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs
index 4e36a755d1..d5826e85b0 100644
--- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs
+++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs
@@ -12,11 +12,6 @@ namespace osu.Game.Beatmaps.ControlPoints
[Serializable]
public class ControlPointInfo
{
- private readonly TimingControlPoint timingSearchPoint = new TimingControlPoint();
- private readonly DifficultyControlPoint difficultySearchPoint = new DifficultyControlPoint();
- private readonly SampleControlPoint sampleSearchPoint = new SampleControlPoint();
- private readonly EffectControlPoint effectSearchPoint = new EffectControlPoint();
-
///
/// All timing points.
///
@@ -46,28 +41,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, difficultySearchPoint);
+ public DifficultyControlPoint DifficultyPointAt(double time) => binarySearch(DifficultyPoints, time);
///
/// 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, effectSearchPoint);
+ public EffectControlPoint EffectPointAt(double time) => binarySearch(EffectPoints, time);
///
/// 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, sampleSearchPoint, SamplePoints.Count > 0 ? SamplePoints[0] : null);
+ public SampleControlPoint SamplePointAt(double time) => binarySearch(SamplePoints, time, SamplePoints.Count > 0 ? SamplePoints[0] : null);
///
/// 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, timingSearchPoint, TimingPoints.Count > 0 ? TimingPoints[0] : null);
+ public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time, TimingPoints.Count > 0 ? TimingPoints[0] : null);
///
/// Finds the maximum BPM represented by any timing control point.
@@ -97,7 +92,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 searchPoint, T prePoint = null)
+ private T binarySearch(SortedList list, double time, T prePoint = null)
where T : ControlPoint, new()
{
if (list == null)
@@ -109,18 +104,23 @@ namespace osu.Game.Beatmaps.ControlPoints
if (time < list[0].Time)
return prePoint ?? new T();
- searchPoint.Time = time;
- int index = list.BinarySearch(searchPoint);
+ int l = 0;
+ int r = list.Count - 1;
- // Check if we've found an exact match (t == time)
- if (index >= 0)
- return list[index];
+ while (l <= r)
+ {
+ int pivot = l + ((r - l) >> 1);
- index = ~index;
+ if (list[pivot].Time < time)
+ l = pivot + 1;
+ else if (list[pivot].Time > time)
+ r = pivot - 1;
+ else
+ return list[pivot];
+ }
- // BinarySearch will return the index of the first element _greater_ than the search
- // This is the inactive point - the active point is the one before it (index - 1)
- return list[index - 1];
+ // l will be the first control point with Time > time, but we want the one before it
+ return list[l - 1];
}
}
}