Skip to content

Commit 97f8dd3

Browse files
committed
Optimise mod comparison function for most common case
1 parent 17f69a4 commit 97f8dd3

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

osu.Server.Queues.ScoreStatisticsProcessor/Commands/Maintenance/MarkNonPreservedScoresCommand.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Dapper;
1111
using McMaster.Extensions.CommandLineUtils;
1212
using MySqlConnector;
13+
using osu.Game.Extensions;
1314
using osu.Server.QueueProcessor;
1415
using osu.Server.Queues.ScoreStatisticsProcessor.Helpers;
1516
using osu.Server.Queues.ScoreStatisticsProcessor.Models;
@@ -155,6 +156,9 @@ private static void formatOutput(SoloScore score, bool delete, string reason)
155156
);
156157
}
157158

159+
private static readonly HashSet<string> a_hash_set = new HashSet<string>();
160+
private static readonly HashSet<string> b_hash_set = new HashSet<string>();
161+
158162
private static bool checkIsUserHigh(IEnumerable<SoloScore> userScores, SoloScore candidate, out HashSet<SoloScore> preservedAlternatives)
159163
{
160164
var scores = userScores.Where(s =>
@@ -200,11 +204,22 @@ private static bool checkIsUserHigh(IEnumerable<SoloScore> userScores, SoloScore
200204

201205
static bool compareMods(SoloScore a, SoloScore b)
202206
{
203-
// Compare non-ordered mods, ignoring any settings applied.
204-
var aMods = new HashSet<string>(a.ScoreData.Mods.Select(m => m.Acronym));
205-
var bMods = new HashSet<string>(b.ScoreData.Mods.Select(m => m.Acronym));
207+
var aMods = a.ScoreData.Mods;
208+
var bMods = b.ScoreData.Mods;
209+
210+
if (aMods.Length == 0 && bMods.Length == 0)
211+
return true;
212+
213+
if (aMods.Length != bMods.Length)
214+
return false;
215+
216+
a_hash_set.Clear();
217+
a_hash_set.AddRange(aMods.Select(m => m.Acronym));
218+
219+
b_hash_set.Clear();
220+
b_hash_set.AddRange(bMods.Select(m => m.Acronym));
206221

207-
return aMods.SetEquals(bMods);
222+
return a_hash_set.SetEquals(b_hash_set);
208223
}
209224
}
210225
}

0 commit comments

Comments
 (0)