1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 23:27:25 +08:00

Simplify implementation of CalculatePerformanceAsync

This commit is contained in:
Bartłomiej Dach 2020-10-12 22:10:02 +02:00
parent 7117fd0fba
commit d4ba9d2682

View File

@ -26,19 +26,14 @@ namespace osu.Game.Scoring
/// <param name="token">An optional <see cref="CancellationToken"/> to cancel the operation.</param>
public async Task<double?> CalculatePerformanceAsync([NotNull] ScoreInfo score, CancellationToken token = default)
{
if (tryGetExisting(score, out var perf, out var lookupKey))
return perf;
var lookupKey = new PerformanceCacheLookup(score);
if (performanceCache.TryGetValue(lookupKey, out double performance))
return performance;
return await computePerformanceAsync(score, lookupKey, token);
}
private bool tryGetExisting(ScoreInfo score, out double performance, out PerformanceCacheLookup lookupKey)
{
lookupKey = new PerformanceCacheLookup(score);
return performanceCache.TryGetValue(lookupKey, out performance);
}
private async Task<double?> computePerformanceAsync(ScoreInfo score, PerformanceCacheLookup lookupKey, CancellationToken token = default)
{
var attributes = await difficultyManager.GetDifficultyAsync(score.Beatmap, score.Ruleset, score.Mods, token);