1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 21:02:54 +08:00

Reduce allocations in ComposerDistanceSnapProvider

This commit is contained in:
Andrei Zavatski 2024-02-19 20:49:56 +03:00
parent 29900353d9
commit c758640311

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions; using osu.Framework.Extensions;
@ -124,12 +123,34 @@ namespace osu.Game.Rulesets.Edit
private (HitObject before, HitObject after)? getObjectsOnEitherSideOfCurrentTime() private (HitObject before, HitObject after)? getObjectsOnEitherSideOfCurrentTime()
{ {
HitObject? lastBefore = playfield.HitObjectContainer.AliveObjects.LastOrDefault(h => h.HitObject.StartTime < editorClock.CurrentTime)?.HitObject; HitObject? lastBefore = null;
foreach (var entry in playfield.HitObjectContainer.AliveEntries)
{
double objTime = entry.Value.HitObject.StartTime;
if (objTime >= editorClock.CurrentTime)
continue;
if (objTime > lastBefore?.StartTime)
lastBefore = entry.Value.HitObject;
}
if (lastBefore == null) if (lastBefore == null)
return null; return null;
HitObject? firstAfter = playfield.HitObjectContainer.AliveObjects.FirstOrDefault(h => h.HitObject.StartTime >= editorClock.CurrentTime)?.HitObject; HitObject? firstAfter = null;
foreach (var entry in playfield.HitObjectContainer.AliveEntries)
{
double objTime = entry.Value.HitObject.StartTime;
if (objTime < editorClock.CurrentTime)
continue;
if (objTime < firstAfter?.StartTime)
firstAfter = entry.Value.HitObject;
}
if (firstAfter == null) if (firstAfter == null)
return null; return null;