replace linq usage in `Previous` and `Next` with more direct computation

This commit is contained in:
tsunyoku 2024-02-10 15:42:55 +00:00
parent 4b847b68a2
commit 901b82384d
1 changed files with 10 additions and 3 deletions

View File

@ -4,7 +4,6 @@
#nullable disable
using System.Collections.Generic;
using System.Linq;
using osu.Game.Rulesets.Objects;
namespace osu.Game.Rulesets.Difficulty.Preprocessing
@ -65,8 +64,16 @@ public DifficultyHitObject(HitObject hitObject, HitObject lastObject, double clo
EndTime = hitObject.GetEndTime() / clockRate;
}
public DifficultyHitObject Previous(int backwardsIndex) => difficultyHitObjects.ElementAtOrDefault(Index - (backwardsIndex + 1));
public DifficultyHitObject Previous(int backwardsIndex)
{
int index = Index - (backwardsIndex + 1);
return index >= 0 && index < difficultyHitObjects.Count ? difficultyHitObjects[index] : default;
}
public DifficultyHitObject Next(int forwardsIndex) => difficultyHitObjects.ElementAtOrDefault(Index + (forwardsIndex + 1));
public DifficultyHitObject Next(int forwardsIndex)
{
int index = Index + (forwardsIndex + 1);
return index >= 0 && index < difficultyHitObjects.Count ? difficultyHitObjects[index] : default;
}
}
}