Skip to content

Commit 6537aec

Browse files
perf: use RemoveRange for batch trim in ClicksPerSecondController
Agent-Logs-Url: https://github.com/winnerspiros/osu/sessions/adbddea2-3da1-47fd-b556-24d1a5d61ad5 Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com>
1 parent c2c3927 commit 6537aec

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

osu.Game/Screens/Play/HUD/ClicksPerSecond/ClicksPerSecondController.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ protected override void Update()
4040
// so we can use binary-search-style trimming instead of per-element RemoveAt.
4141

4242
// Trim future timestamps caused by rewinding (remove from the end in one batch).
43-
while (timestamps.Count > 0 && timestamps[^1] > latestValidTime)
44-
timestamps.RemoveAt(timestamps.Count - 1);
43+
// RemoveRange from the end is a single operation vs repeated RemoveAt calls.
44+
int trimStart = timestamps.Count;
45+
46+
while (trimStart > 0 && timestamps[trimStart - 1] > latestValidTime)
47+
trimStart--;
48+
49+
if (trimStart < timestamps.Count)
50+
timestamps.RemoveRange(trimStart, timestamps.Count - trimStart);
4551

4652
// Count timestamps within the valid 1-second window.
4753
// Since the list is in chronological order, scan backwards until we leave the window.

0 commit comments

Comments
 (0)