From a32389b281bdb8a3870b3865ca80554d1b584883 Mon Sep 17 00:00:00 2001 From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com> Date: Tue, 30 Aug 2022 02:18:05 -0500 Subject: [PATCH] Switch to ReadOnlyCollection --- .../ScheduledTasks/AnalyzeEpisodesTask.cs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs index 40c0157..5edc7a9 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/AnalyzeEpisodesTask.cs @@ -152,7 +152,7 @@ public class AnalyzeEpisodesTask : IScheduledTask try { - var episodes = new Collection(season.Value); + var episodes = new ReadOnlyCollection(season.Value); // Increment totalProcessed by the number of episodes in this season that were actually analyzed // (instead of just using the number of episodes in the current season). @@ -234,7 +234,7 @@ public class AnalyzeEpisodesTask : IScheduledTask /// Cancellation token provided by the scheduled task. /// Number of episodes from the provided season that were analyzed. private int AnalyzeSeason( - Collection episodes, + ReadOnlyCollection episodes, CancellationToken cancellationToken) { // All intros for this season. @@ -243,8 +243,8 @@ public class AnalyzeEpisodesTask : IScheduledTask // Cache of all fingerprints for this season. var fingerprintCache = new Dictionary(); - // Original episode queue. - var originalEpisodes = new List(episodes); + // Episode analysis queue. + var episodeAnalysisQueue = new List(episodes); /* Don't analyze specials or seasons with an insufficient number of episodes. * A season with only 1 episode can't be analyzed as it would compare the episode to itself, @@ -252,7 +252,7 @@ public class AnalyzeEpisodesTask : IScheduledTask */ if (episodes.Count < 2 || episodes[0].SeasonNumber == 0) { - return originalEpisodes.Count; + return episodes.Count; } var first = episodes[0]; @@ -264,7 +264,7 @@ public class AnalyzeEpisodesTask : IScheduledTask first.SeasonNumber); // Compute fingerprints for all episodes in the season - foreach (var episode in episodes) + foreach (var episode in episodeAnalysisQueue) { try { @@ -280,14 +280,14 @@ public class AnalyzeEpisodesTask : IScheduledTask } // While there are still episodes in the queue - while (episodes.Count > 0) + while (episodeAnalysisQueue.Count > 0) { // Pop the first episode from the queue - var currentEpisode = episodes[0]; - episodes.RemoveAt(0); + var currentEpisode = episodeAnalysisQueue[0]; + episodeAnalysisQueue.RemoveAt(0); // Search through all remaining episodes. - foreach (var remainingEpisode in episodes) + foreach (var remainingEpisode in episodeAnalysisQueue) { // Compare the current episode to all remaining episodes in the queue. var (currentIntro, remainingIntro) = CompareEpisodes( @@ -326,9 +326,7 @@ public class AnalyzeEpisodesTask : IScheduledTask } // Adjust all introduction end times so that they end at silence. - seasonIntros = AdjustIntroEndTimes( - new ReadOnlyCollection(originalEpisodes), - seasonIntros); + seasonIntros = AdjustIntroEndTimes(episodes, seasonIntros); // Ensure only one thread at a time can update the shared intro dictionary. lock (_introsLock) @@ -344,7 +342,7 @@ public class AnalyzeEpisodesTask : IScheduledTask Plugin.Instance!.SaveTimestamps(); } - return originalEpisodes.Count; + return episodes.Count; } ///