1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 06:42:54 +08:00

Merge pull request #14509 from peppy/replay-frame-comparison-array-overhead-reduction

Avoid unnecessary array/LINQ operations when replay frames have no action changes
This commit is contained in:
Salman Ahmed 2021-08-26 09:54:36 +03:00 committed by GitHub
commit fb732785d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,9 +42,24 @@ namespace osu.Game.Input.Handlers
if (!(state is RulesetInputManagerInputState<T> inputState))
throw new InvalidOperationException($"{nameof(ReplayState<T>)} should only be applied to a {nameof(RulesetInputManagerInputState<T>)}");
var lastPressed = inputState.LastReplayState?.PressedActions ?? new List<T>();
var released = lastPressed.Except(PressedActions).ToArray();
var pressed = PressedActions.Except(lastPressed).ToArray();
T[] released = Array.Empty<T>();
T[] pressed = Array.Empty<T>();
var lastPressed = inputState.LastReplayState?.PressedActions;
if (lastPressed == null || lastPressed.Count == 0)
{
pressed = PressedActions.ToArray();
}
else if (PressedActions.Count == 0)
{
released = lastPressed.ToArray();
}
else if (!lastPressed.SequenceEqual(PressedActions))
{
released = lastPressed.Except(PressedActions).ToArray();
pressed = PressedActions.Except(lastPressed).ToArray();
}
inputState.LastReplayState = this;