Use Array.Empty and fix a few multiple enumerations

pull/5521/head
Stepan Goremykin 2 years ago committed by GitHub
parent c41aec5f77
commit 11d91faaad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,7 +16,7 @@ namespace NzbDrone.Common.Composition
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ContainerResolveEventHandler); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ContainerResolveEventHandler);
} }
public static IEnumerable<Assembly> Load(IEnumerable<string> assemblyNames) public static IList<Assembly> Load(IList<string> assemblyNames)
{ {
var toLoad = assemblyNames.ToList(); var toLoad = assemblyNames.ToList();
toLoad.Add("Sonarr.Common"); toLoad.Add("Sonarr.Common");
@ -28,8 +28,9 @@ namespace NzbDrone.Common.Composition
var startupPath = AppDomain.CurrentDomain.BaseDirectory; var startupPath = AppDomain.CurrentDomain.BaseDirectory;
return toLoad.Select(x => return toLoad
AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.Combine(startupPath, $"{x}.dll"))); .Select(x => AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.Combine(startupPath, $"{x}.dll")))
.ToList();
} }
private static Assembly ContainerResolveEventHandler(object sender, ResolveEventArgs args) private static Assembly ContainerResolveEventHandler(object sender, ResolveEventArgs args)

@ -15,14 +15,14 @@ namespace NzbDrone.Common.OAuth
{ {
get get
{ {
var parameters = this.Where(p => p.Name.Equals(name)); var parameters = this.Where(p => p.Name.Equals(name)).ToArray();
if (parameters.Empty()) if (parameters.Empty())
{ {
return null; return null;
} }
if (parameters.Count() == 1) if (parameters.Length == 1)
{ {
return parameters.Single(); return parameters.Single();
} }

@ -39,7 +39,7 @@ namespace NzbDrone.Core.DataAugmentation.DailySeries
catch (Exception ex) catch (Exception ex)
{ {
_logger.Warn(ex, "Failed to get Daily Series"); _logger.Warn(ex, "Failed to get Daily Series");
return new List<int>(); return Array.Empty<int>();
} }
} }
} }

@ -111,7 +111,7 @@ namespace NzbDrone.Core.Datastore
{ {
if (!ids.Any()) if (!ids.Any())
{ {
return new List<TModel>(); return Array.Empty<TModel>();
} }
var result = Query(x => ids.Contains(x.Id)); var result = Query(x => ids.Contains(x.Id));

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Http; using System.Net.Http;
using NLog; using NLog;
@ -61,7 +62,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
catch (DownloadClientException e) catch (DownloadClientException e)
{ {
_logger.Error(e); _logger.Error(e);
return new List<DownloadStationTask>(); return Array.Empty<DownloadStationTask>();
} }
} }

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
@ -102,7 +103,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
catch (DownloadClientException e) catch (DownloadClientException e)
{ {
_logger.Error(e); _logger.Error(e);
return new List<DownloadStationTask>(); return Array.Empty<DownloadStationTask>();
} }
} }

@ -136,7 +136,7 @@ namespace NzbDrone.Core.Extras.Metadata
if (seriesFolder.IsNullOrWhiteSpace() && seasonFolder.IsNullOrWhiteSpace()) if (seriesFolder.IsNullOrWhiteSpace() && seasonFolder.IsNullOrWhiteSpace())
{ {
return new List<MetadataFile>(); return Array.Empty<MetadataFile>();
} }
var files = new List<MetadataFile>(); var files = new List<MetadataFile>();

@ -51,7 +51,7 @@ namespace NzbDrone.Core.ImportLists.Simkl
// Check to see if user has any activity since last sync, if not return empty to avoid work // Check to see if user has any activity since last sync, if not return empty to avoid work
if (lastFetch.HasValue && lastActivity < lastFetch.Value.AddHours(-2)) if (lastFetch.HasValue && lastActivity < lastFetch.Value.AddHours(-2))
{ {
return new List<ImportListItemInfo>(); return Array.Empty<ImportListItemInfo>();
} }
var generator = GetRequestGenerator(); var generator = GetRequestGenerator();

@ -43,7 +43,7 @@ namespace NzbDrone.Core.Indexers
{ {
if (!SupportsRss) if (!SupportsRss)
{ {
return new List<ReleaseInfo>(); return Array.Empty<ReleaseInfo>();
} }
return FetchReleases(g => g.GetRecentRequests(), true); return FetchReleases(g => g.GetRecentRequests(), true);
@ -53,7 +53,7 @@ namespace NzbDrone.Core.Indexers
{ {
if (!SupportsSearch) if (!SupportsSearch)
{ {
return new List<ReleaseInfo>(); return Array.Empty<ReleaseInfo>();
} }
return FetchReleases(g => g.GetSearchRequests(searchCriteria)); return FetchReleases(g => g.GetSearchRequests(searchCriteria));
@ -63,7 +63,7 @@ namespace NzbDrone.Core.Indexers
{ {
if (!SupportsSearch) if (!SupportsSearch)
{ {
return new List<ReleaseInfo>(); return Array.Empty<ReleaseInfo>();
} }
return FetchReleases(g => g.GetSearchRequests(searchCriteria)); return FetchReleases(g => g.GetSearchRequests(searchCriteria));
@ -73,7 +73,7 @@ namespace NzbDrone.Core.Indexers
{ {
if (!SupportsSearch) if (!SupportsSearch)
{ {
return new List<ReleaseInfo>(); return Array.Empty<ReleaseInfo>();
} }
return FetchReleases(g => g.GetSearchRequests(searchCriteria)); return FetchReleases(g => g.GetSearchRequests(searchCriteria));
@ -83,7 +83,7 @@ namespace NzbDrone.Core.Indexers
{ {
if (!SupportsSearch) if (!SupportsSearch)
{ {
return new List<ReleaseInfo>(); return Array.Empty<ReleaseInfo>();
} }
return FetchReleases(g => g.GetSearchRequests(searchCriteria)); return FetchReleases(g => g.GetSearchRequests(searchCriteria));
@ -93,7 +93,7 @@ namespace NzbDrone.Core.Indexers
{ {
if (!SupportsSearch) if (!SupportsSearch)
{ {
return new List<ReleaseInfo>(); return Array.Empty<ReleaseInfo>();
} }
return FetchReleases(g => g.GetSearchRequests(searchCriteria)); return FetchReleases(g => g.GetSearchRequests(searchCriteria));
@ -103,7 +103,7 @@ namespace NzbDrone.Core.Indexers
{ {
if (!SupportsSearch) if (!SupportsSearch)
{ {
return new List<ReleaseInfo>(); return Array.Empty<ReleaseInfo>();
} }
return FetchReleases(g => g.GetSearchRequests(searchCriteria)); return FetchReleases(g => g.GetSearchRequests(searchCriteria));

@ -84,7 +84,7 @@ namespace NzbDrone.Core.Indexers
if (!PostProcess(indexerResponse, items, releases)) if (!PostProcess(indexerResponse, items, releases))
{ {
return new List<ReleaseInfo>(); return Array.Empty<ReleaseInfo>();
} }
return releases; return releases;

@ -51,12 +51,13 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownload, DownloadClientItem downloadClientItem = null, ImportMode importMode = ImportMode.Auto) public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownload, DownloadClientItem downloadClientItem = null, ImportMode importMode = ImportMode.Auto)
{ {
var qualifiedImports = decisions.Where(c => c.Approved) var qualifiedImports = decisions
.GroupBy(c => c.LocalEpisode.Series.Id, (i, s) => s .Where(decision => decision.Approved)
.OrderByDescending(c => c.LocalEpisode.Quality, new QualityModelComparer(s.First().LocalEpisode.Series.QualityProfile)) .GroupBy(decision => decision.LocalEpisode.Series.Id)
.ThenByDescending(c => c.LocalEpisode.Size)) .SelectMany(group => group
.SelectMany(c => c) .OrderByDescending(decision => decision.LocalEpisode.Quality, new QualityModelComparer(group.First().LocalEpisode.Series.QualityProfile))
.ToList(); .ThenByDescending(decision => decision.LocalEpisode.Size))
.ToList();
var importResults = new List<ImportResult>(); var importResults = new List<ImportResult>();

@ -186,7 +186,7 @@ namespace NzbDrone.Core.Tv
} }
} }
private void AdjustDirectToDvdAirDate(Series series, IEnumerable<Episode> allEpisodes) private void AdjustDirectToDvdAirDate(Series series, IList<Episode> allEpisodes)
{ {
if (series.Status == SeriesStatusType.Ended && allEpisodes.All(v => !v.AirDateUtc.HasValue) && series.FirstAired.HasValue) if (series.Status == SeriesStatusType.Ended && allEpisodes.All(v => !v.AirDateUtc.HasValue) && series.FirstAired.HasValue)
{ {

@ -45,11 +45,11 @@ namespace Sonarr.Api.V3
[Produces("application/json")] [Produces("application/json")]
public List<TProviderResource> GetAll() public List<TProviderResource> GetAll()
{ {
var providerDefinitions = _providerFactory.All().OrderBy(p => p.ImplementationName); var providerDefinitions = _providerFactory.All();
var result = new List<TProviderResource>(providerDefinitions.Count()); var result = new List<TProviderResource>(providerDefinitions.Count);
foreach (var definition in providerDefinitions) foreach (var definition in providerDefinitions.OrderBy(p => p.ImplementationName))
{ {
_providerFactory.SetProviderCharacteristics(definition); _providerFactory.SetProviderCharacteristics(definition);

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using FluentValidation; using FluentValidation;
using FluentValidation.Results; using FluentValidation.Results;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -87,7 +88,8 @@ namespace Sonarr.Http.REST
} }
} }
var attributes = descriptor.MethodInfo.CustomAttributes; var attributes = descriptor.MethodInfo.CustomAttributes as IReadOnlyCollection<CustomAttributeData> ??
descriptor.MethodInfo.CustomAttributes.ToArray();
if (attributes.Any(x => VALIDATE_ID_ATTRIBUTES.Contains(x.AttributeType)) && !skipValidate) if (attributes.Any(x => VALIDATE_ID_ATTRIBUTES.Contains(x.AttributeType)) && !skipValidate)
{ {
if (context.ActionArguments.TryGetValue("id", out var idObj)) if (context.ActionArguments.TryGetValue("id", out var idObj))

Loading…
Cancel
Save