mirror of https://github.com/ppy/osu
Reduce dictionary lookups
This commit is contained in:
parent
310cf830d4
commit
7aac0e59a8
|
@ -44,18 +44,18 @@ private void load()
|
||||||
/// <returns>The recommended difficulty, or null if a recommendation could not be provided.</returns>
|
/// <returns>The recommended difficulty, or null if a recommendation could not be provided.</returns>
|
||||||
public BeatmapInfo GetRecommendedBeatmap(IEnumerable<BeatmapInfo> beatmaps)
|
public BeatmapInfo GetRecommendedBeatmap(IEnumerable<BeatmapInfo> beatmaps)
|
||||||
{
|
{
|
||||||
if (!recommendedStarDifficulty.ContainsKey(ruleset.Value))
|
if (recommendedStarDifficulty.TryGetValue(ruleset.Value, out var stars))
|
||||||
{
|
{
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return beatmaps.OrderBy(b =>
|
return beatmaps.OrderBy(b =>
|
||||||
{
|
{
|
||||||
var difference = b.StarDifficulty - recommendedStarDifficulty[ruleset.Value];
|
var difference = b.StarDifficulty - stars;
|
||||||
return difference >= 0 ? difference * 2 : difference * -1; // prefer easier over harder
|
return difference >= 0 ? difference * 2 : difference * -1; // prefer easier over harder
|
||||||
}).FirstOrDefault();
|
}).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private void calculateRecommendedDifficulties()
|
private void calculateRecommendedDifficulties()
|
||||||
{
|
{
|
||||||
rulesets.AvailableRulesets.ForEach(rulesetInfo =>
|
rulesets.AvailableRulesets.ForEach(rulesetInfo =>
|
||||||
|
|
Loading…
Reference in New Issue