From 18e3f8c233da2ed3eb8b859944994d39f9f54512 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 8 Feb 2021 19:03:19 +0900 Subject: [PATCH] Sort beat lengths rather than linear search --- osu.Game/Beatmaps/Beatmap.cs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 434bff14b5..e5b6a4bc44 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -55,7 +55,7 @@ namespace osu.Game.Beatmaps // Note: This is more accurate and may present different results because osu-stable didn't have the ability to calculate slider durations in this context. double lastTime = HitObjects.LastOrDefault()?.GetEndTime() ?? ControlPointInfo.TimingPoints.LastOrDefault()?.Time ?? 0; - var beatLengthsAndDurations = + var mostCommon = // Construct a set of (beatLength, duration) tuples for each individual timing point. ControlPointInfo.TimingPoints.Select((t, i) => { @@ -68,23 +68,10 @@ namespace osu.Game.Beatmaps // Aggregate durations into a set of (beatLength, duration) tuples for each beat length .GroupBy(t => Math.Round(t.beatLength * 1000) / 1000) .Select(g => (beatLength: g.Key, duration: g.Sum(t => t.duration))) - // And if there are no timing points, use a default. - .DefaultIfEmpty((TimingControlPoint.DEFAULT_BEAT_LENGTH, 0)); + // Get the most common one, or 0 as a suitable default + .OrderByDescending(i => i.duration).FirstOrDefault(); - // Find the single beat length with the maximum aggregate duration. - double maxDurationBeatLength = double.NegativeInfinity; - double maxDuration = double.NegativeInfinity; - - foreach (var (beatLength, duration) in beatLengthsAndDurations) - { - if (duration > maxDuration) - { - maxDuration = duration; - maxDurationBeatLength = beatLength; - } - } - - return maxDurationBeatLength; + return mostCommon.beatLength; } IBeatmap IBeatmap.Clone() => Clone();