Simplify implementation of CalculatePerformanceAsync

This commit is contained in:
Bartłomiej Dach 2020-10-12 22:10:02 +02:00
parent 7117fd0fba
commit d4ba9d2682
1 changed files with 4 additions and 9 deletions

View File

@ -26,19 +26,14 @@ public class ScorePerformanceManager : Component
/// <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);