From 3d8faea4b073718900da16d0a0b522fb700aed9d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 7 Sep 2021 18:52:25 +0900 Subject: [PATCH] Simplify nesting of `OrderByTotalScoreAsync` --- osu.Game/Scoring/ScoreManager.cs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 2cda8959f4d0..81e701f001f2 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -116,25 +116,20 @@ public async Task OrderByTotalScoreAsync(ScoreInfo[] scores, Cancel { var difficultyCache = difficulties?.Invoke(); - if (difficultyCache == null) - return orderByTotalScore(scores); - - // Compute difficulties asynchronously first to prevent blocking via the GetTotalScore() call below. - foreach (var s in scores) + if (difficultyCache != null) { - await difficultyCache.GetDifficultyAsync(s.Beatmap, s.Ruleset, s.Mods, cancellationToken).ConfigureAwait(false); - cancellationToken.ThrowIfCancellationRequested(); + // Compute difficulties asynchronously first to prevent blocking via the GetTotalScore() call below. + foreach (var s in scores) + { + await difficultyCache.GetDifficultyAsync(s.Beatmap, s.Ruleset, s.Mods, cancellationToken).ConfigureAwait(false); + cancellationToken.ThrowIfCancellationRequested(); + } } - return orderByTotalScore(scores); - - ScoreInfo[] orderByTotalScore(IEnumerable incoming) - { - // We're calling .Result, but this should not be a blocking call due to the above GetDifficultyAsync() calls. - return incoming.OrderByDescending(s => GetTotalScoreAsync(s, cancellationToken: cancellationToken).Result) - .ThenBy(s => s.OnlineScoreID) - .ToArray(); - } + // We're calling .Result, but this should not be a blocking call due to the above GetDifficultyAsync() calls. + return scores.OrderByDescending(s => GetTotalScoreAsync(s, cancellationToken: cancellationToken).Result) + .ThenBy(s => s.OnlineScoreID) + .ToArray(); } ///