diff options
| author | Bond-009 <bond.009@outlook.com> | 2024-04-30 21:32:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-30 13:32:59 -0600 |
| commit | 3feb3f81bfe848aa829e7c129bee3cd060c23c05 (patch) | |
| tree | c247db8e30d1cc52bc6735d45d86eff8955ee7e9 /src | |
| parent | 5dc6bb4910cfdc7f40ad83d647172d743e6e0595 (diff) | |
More efficient array creation (#11468)
Diffstat (limited to 'src')
| -rw-r--r-- | src/Jellyfin.LiveTv/Channels/ChannelManager.cs | 2 | ||||
| -rw-r--r-- | src/Jellyfin.LiveTv/Listings/ListingsManager.cs | 14 | ||||
| -rw-r--r-- | src/Jellyfin.LiveTv/LiveTvManager.cs | 2 | ||||
| -rw-r--r-- | src/Jellyfin.LiveTv/Timers/ItemDataProvider.cs | 12 | ||||
| -rw-r--r-- | src/Jellyfin.LiveTv/TunerHosts/TunerHostManager.cs | 7 |
5 files changed, 13 insertions, 24 deletions
diff --git a/src/Jellyfin.LiveTv/Channels/ChannelManager.cs b/src/Jellyfin.LiveTv/Channels/ChannelManager.cs index cce2911dc..83f68ab50 100644 --- a/src/Jellyfin.LiveTv/Channels/ChannelManager.cs +++ b/src/Jellyfin.LiveTv/Channels/ChannelManager.cs @@ -1130,7 +1130,7 @@ namespace Jellyfin.LiveTv.Channels { if (!item.Tags.Contains("livestream", StringComparison.OrdinalIgnoreCase)) { - item.Tags = item.Tags.Concat(new[] { "livestream" }).ToArray(); + item.Tags = [..item.Tags, "livestream"]; _logger.LogDebug("Forcing update due to Tags {0}", item.Name); forceUpdate = true; } diff --git a/src/Jellyfin.LiveTv/Listings/ListingsManager.cs b/src/Jellyfin.LiveTv/Listings/ListingsManager.cs index 87f47611e..dfd376092 100644 --- a/src/Jellyfin.LiveTv/Listings/ListingsManager.cs +++ b/src/Jellyfin.LiveTv/Listings/ListingsManager.cs @@ -60,14 +60,13 @@ public class ListingsManager : IListingsManager var config = _config.GetLiveTvConfiguration(); - var list = config.ListingProviders.ToList(); - int index = list.FindIndex(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); + var list = config.ListingProviders; + int index = Array.FindIndex(list, i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); if (index == -1 || string.IsNullOrWhiteSpace(info.Id)) { info.Id = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); - list.Add(info); - config.ListingProviders = list.ToArray(); + config.ListingProviders = [..list, info]; } else { @@ -236,13 +235,12 @@ public class ListingsManager : IListingsManager if (!string.Equals(tunerChannelNumber, providerChannelNumber, StringComparison.OrdinalIgnoreCase)) { - var list = listingsProviderInfo.ChannelMappings.ToList(); - list.Add(new NameValuePair + var newItem = new NameValuePair { Name = tunerChannelNumber, Value = providerChannelNumber - }); - listingsProviderInfo.ChannelMappings = list.ToArray(); + }; + listingsProviderInfo.ChannelMappings = [..listingsProviderInfo.ChannelMappings, newItem]; } _config.SaveConfiguration("livetv", config); diff --git a/src/Jellyfin.LiveTv/LiveTvManager.cs b/src/Jellyfin.LiveTv/LiveTvManager.cs index c19d8195c..0c85dc434 100644 --- a/src/Jellyfin.LiveTv/LiveTvManager.cs +++ b/src/Jellyfin.LiveTv/LiveTvManager.cs @@ -939,7 +939,7 @@ namespace Jellyfin.LiveTv { var internalChannelId = _tvDtoService.GetInternalChannelId(i.Item2.Name, i.Item1.ChannelId); var channel = _libraryManager.GetItemById(internalChannelId); - channelName = channel is null ? null : channel.Name; + channelName = channel?.Name; } return _tvDtoService.GetSeriesTimerInfoDto(i.Item1, i.Item2, channelName); diff --git a/src/Jellyfin.LiveTv/Timers/ItemDataProvider.cs b/src/Jellyfin.LiveTv/Timers/ItemDataProvider.cs index 18e4810a2..9e7323f5b 100644 --- a/src/Jellyfin.LiveTv/Timers/ItemDataProvider.cs +++ b/src/Jellyfin.LiveTv/Timers/ItemDataProvider.cs @@ -115,11 +115,7 @@ namespace Jellyfin.LiveTv.Timers throw new ArgumentException("item already exists", nameof(item)); } - int oldLen = _items.Length; - var newList = new T[oldLen + 1]; - _items.CopyTo(newList, 0); - newList[oldLen] = item; - _items = newList; + _items = [.._items, item]; SaveList(); } @@ -134,11 +130,7 @@ namespace Jellyfin.LiveTv.Timers int index = Array.FindIndex(_items, i => EqualityComparer(i, item)); if (index == -1) { - int oldLen = _items.Length; - var newList = new T[oldLen + 1]; - _items.CopyTo(newList, 0); - newList[oldLen] = item; - _items = newList; + _items = [.._items, item]; } else { diff --git a/src/Jellyfin.LiveTv/TunerHosts/TunerHostManager.cs b/src/Jellyfin.LiveTv/TunerHosts/TunerHostManager.cs index 60be19c68..473f00153 100644 --- a/src/Jellyfin.LiveTv/TunerHosts/TunerHostManager.cs +++ b/src/Jellyfin.LiveTv/TunerHosts/TunerHostManager.cs @@ -76,14 +76,13 @@ public class TunerHostManager : ITunerHostManager var config = _config.GetLiveTvConfiguration(); - var list = config.TunerHosts.ToList(); - var index = list.FindIndex(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); + var list = config.TunerHosts; + var index = Array.FindIndex(list, i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); if (index == -1 || string.IsNullOrWhiteSpace(info.Id)) { info.Id = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture); - list.Add(info); - config.TunerHosts = list.ToArray(); + config.TunerHosts = [..list, info]; } else { |
