From d7ff3d77eb538b598e9878fa3cd814daf15fc499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 18 Aug 2020 19:44:41 +0200 Subject: [PATCH] Slightly optimise and de-branch repetition pattern recognition --- .../Difficulty/Skills/Colour.cs | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/Difficulty/Skills/Colour.cs b/osu.Game.Rulesets.Taiko/Difficulty/Skills/Colour.cs index 2a72f884d1..dd8b536afc 100644 --- a/osu.Game.Rulesets.Taiko/Difficulty/Skills/Colour.cs +++ b/osu.Game.Rulesets.Taiko/Difficulty/Skills/Colour.cs @@ -87,28 +87,29 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Skills for (int start = monoHistory.Count - l - 1; start >= 0; start--) { - bool samePattern = true; + if (!isSamePattern(start, l)) + continue; - for (int i = 0; i < l; i++) - { - if (monoHistory[start + i] != monoHistory[monoHistory.Count - l + i]) - { - samePattern = false; - } - } - - if (samePattern) // Repetition found! - { - int notesSince = 0; - for (int i = start; i < monoHistory.Count; i++) notesSince += monoHistory[i]; - penalty *= repetitionPenalty(notesSince); - break; - } + int notesSince = 0; + for (int i = start; i < monoHistory.Count; i++) notesSince += monoHistory[i]; + penalty *= repetitionPenalty(notesSince); + break; } return penalty; } + private bool isSamePattern(int start, int l) + { + for (int i = 0; i < l; i++) + { + if (monoHistory[start + i] != monoHistory[monoHistory.Count - l + i]) + return false; + } + + return true; + } + private double repetitionPenalty(int notesSince) => Math.Min(1.0, 0.032 * notesSince); } }