From 3b5bf391da57e4ed3efcfd60f6e6fd3724f35b6d Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 25 Feb 2025 22:55:55 +0900 Subject: [PATCH] Arrays instead of enumerables --- .../Visual/Ranking/TestSceneResultsScreen.cs | 21 +++++++++---------- .../Spectate/MultiSpectatorResultsScreen.cs | 5 ++--- .../Playlists/PlaylistItemResultsScreen.cs | 6 +++--- .../PlaylistItemScoreResultsScreen.cs | 3 +-- .../PlaylistItemUserBestResultsScreen.cs | 3 +-- osu.Game/Screens/Ranking/ResultsScreen.cs | 10 ++++----- osu.Game/Screens/Ranking/SoloResultsScreen.cs | 4 ++-- 7 files changed, 24 insertions(+), 28 deletions(-) diff --git a/osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs b/osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs index 4acbdb4a76..b19288fd99 100644 --- a/osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs +++ b/osu.Game.Tests/Visual/Ranking/TestSceneResultsScreen.cs @@ -4,7 +4,6 @@ #nullable disable using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using NUnit.Framework; @@ -415,19 +414,19 @@ namespace osu.Game.Tests.Visual.Ranking RetryOverlay = InternalChildren.OfType().SingleOrDefault(); } - protected override Task> FetchScores() + protected override Task FetchScores() { - var scores = new List(); + var scores = new ScoreInfo[20]; - for (int i = 0; i < 20; i++) + for (int i = 0; i < scores.Length; i++) { var score = TestResources.CreateTestScoreInfo(); score.TotalScore += 10 - i; score.HasOnlineReplay = true; - scores.Add(score); + scores[i] = score; } - return Task.FromResult>(scores); + return Task.FromResult(scores); } } @@ -443,19 +442,19 @@ namespace osu.Game.Tests.Visual.Ranking this.fetchWaitTask = fetchWaitTask ?? Task.CompletedTask; } - protected override Task> FetchScores() + protected override Task FetchScores() { - return Task.Run>(async () => + return Task.Run(async () => { await fetchWaitTask; - var scores = new List(); + var scores = new ScoreInfo[20]; - for (int i = 0; i < 20; i++) + for (int i = 0; i < scores.Length; i++) { var score = TestResources.CreateTestScoreInfo(); score.TotalScore += 10 - i; - scores.Add(score); + scores[i] = score; } Schedule(() => FetchCompleted = true); diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorResultsScreen.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorResultsScreen.cs index 6e2f90e3b5..3cf1661c8d 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorResultsScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorResultsScreen.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using System.Threading.Tasks; using osu.Game.Scoring; using osu.Game.Screens.Play; @@ -22,8 +21,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate Scheduler.AddDelayed(() => StatisticsPanel.ToggleVisibility(), 1000); } - protected override Task> FetchScores() => Task.FromResult>([]); + protected override Task FetchScores() => Task.FromResult([]); - protected override Task> FetchNextPage(int direction) => Task.FromResult>([]); + protected override Task FetchNextPage(int direction) => Task.FromResult([]); } } diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemResultsScreen.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemResultsScreen.cs index e9ba3bdb70..0063bcd5f5 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemResultsScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemResultsScreen.cs @@ -83,7 +83,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists protected abstract APIRequest CreateScoreRequest(); - protected override async Task> FetchScores() + protected override async Task FetchScores() { // This performs two requests: // 1. A request to show the relevant score (and scores around). @@ -141,7 +141,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists } } - protected override async Task> FetchNextPage(int direction) + protected override async Task FetchNextPage(int direction) { Debug.Assert(direction == 1 || direction == -1); @@ -165,7 +165,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists /// /// Does not queue the request. /// An optional score pivot to retrieve scores around. Can be null to retrieve scores from the highest score. - private async Task> fetchScoresAround(MultiplayerScores? pivot = null) + private async Task fetchScoresAround(MultiplayerScores? pivot = null) { var requestTaskSource = new TaskCompletionSource(); var indexReq = pivot != null diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemScoreResultsScreen.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemScoreResultsScreen.cs index 7f386cd293..74b12b6d3c 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemScoreResultsScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemScoreResultsScreen.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using System.Linq; using osu.Game.Online.API; using osu.Game.Online.Rooms; @@ -30,7 +29,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists protected override APIRequest CreateScoreRequest() => new ShowPlaylistScoreRequest(RoomId, PlaylistItem.ID, scoreId); - protected override void OnScoresAdded(IEnumerable scores) + protected override void OnScoresAdded(ScoreInfo[] scores) { base.OnScoresAdded(scores); SelectedScore.Value ??= scores.SingleOrDefault(s => s.OnlineID == scoreId); diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemUserBestResultsScreen.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemUserBestResultsScreen.cs index faeef93b71..866b094178 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemUserBestResultsScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistItemUserBestResultsScreen.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using System.Linq; using osu.Game.Online.API; using osu.Game.Online.Rooms; @@ -24,7 +23,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists protected override APIRequest CreateScoreRequest() => new ShowPlaylistUserScoreRequest(RoomId, PlaylistItem.ID, userId); - protected override void OnScoresAdded(IEnumerable scores) + protected override void OnScoresAdded(ScoreInfo[] scores) { base.OnScoresAdded(scores); diff --git a/osu.Game/Screens/Ranking/ResultsScreen.cs b/osu.Game/Screens/Ranking/ResultsScreen.cs index ce86ac0815..cfee2aa77d 100644 --- a/osu.Game/Screens/Ranking/ResultsScreen.cs +++ b/osu.Game/Screens/Ranking/ResultsScreen.cs @@ -246,7 +246,7 @@ namespace osu.Game.Screens.Ranking if (lastFetchCompleted) { - Task> nextPageTask = Task.FromResult>([]); + Task nextPageTask = Task.FromResult([]); if (ScorePanelList.IsScrolledToStart) nextPageTask = FetchNextPage(-1); @@ -322,13 +322,13 @@ namespace osu.Game.Screens.Ranking /// /// Performs a fetch/refresh of scores to be displayed. /// - protected virtual Task> FetchScores() => Task.FromResult>([]); + protected virtual Task FetchScores() => Task.FromResult([]); /// /// Performs a fetch of the next page of scores. This is invoked every frame. /// /// The fetch direction. -1 to fetch scores greater than the current start of the list, and 1 to fetch scores lower than the current end of the list. - protected virtual Task> FetchNextPage(int direction) => Task.FromResult>([]); + protected virtual Task FetchNextPage(int direction) => Task.FromResult([]); /// /// Creates the to be used to display extended information about scores. @@ -340,7 +340,7 @@ namespace osu.Game.Screens.Ranking : new StatisticsPanel(); } - private void addScores(IEnumerable scores) => Schedule(() => + private void addScores(ScoreInfo[] scores) => Schedule(() => { foreach (var s in scores) { @@ -365,7 +365,7 @@ namespace osu.Game.Screens.Ranking /// Invoked after online scores are fetched and added to the list. /// /// The scores that were added. - protected virtual void OnScoresAdded(IEnumerable scores) + protected virtual void OnScoresAdded(ScoreInfo[] scores) { } diff --git a/osu.Game/Screens/Ranking/SoloResultsScreen.cs b/osu.Game/Screens/Ranking/SoloResultsScreen.cs index 0593d5f91f..9fdffce644 100644 --- a/osu.Game/Screens/Ranking/SoloResultsScreen.cs +++ b/osu.Game/Screens/Ranking/SoloResultsScreen.cs @@ -31,7 +31,7 @@ namespace osu.Game.Screens.Ranking { } - protected override async Task> FetchScores() + protected override async Task FetchScores() { Debug.Assert(Score != null); @@ -70,7 +70,7 @@ namespace osu.Game.Screens.Ranking } } - return toDisplay; + return toDisplay.ToArray(); } catch (OperationCanceledException) {