From 08ee2f7e32e647e232cc15b8a96f501d3b3bf5f9 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 9 Jan 2023 21:39:55 -0600 Subject: [PATCH] Remove unnecessary assignments to default type value The .NET runtime initializes all fields of reference types to their default values before running the constructor. In most cases, explicitly initializing a field to its default value in a constructor is redundant, adding maintenance costs and potentially degrading performance --- .editorconfig | 1 - .../TPL/LimitedConcurrencyLevelTaskScheduler.cs | 2 +- src/NzbDrone.Core/Datastore/WhereBuilder.cs | 6 +++--- src/NzbDrone.Core/HealthCheck/HealthCheckService.cs | 4 ++-- src/NzbDrone.Core/Indexers/IndexerDefinition.cs | 2 +- src/NzbDrone.Core/Indexers/TorrentRssParser.cs | 2 +- src/NzbDrone.Mono/Disk/ProcMountProvider.cs | 2 +- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9f651be38..15f6b66d0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -183,7 +183,6 @@ dotnet_diagnostic.CA1720.severity = suggestion dotnet_diagnostic.CA1721.severity = suggestion dotnet_diagnostic.CA1724.severity = suggestion dotnet_diagnostic.CA1725.severity = suggestion -dotnet_diagnostic.CA1805.severity = suggestion dotnet_diagnostic.CA1806.severity = suggestion dotnet_diagnostic.CA1810.severity = suggestion dotnet_diagnostic.CA1812.severity = suggestion diff --git a/src/NzbDrone.Common/TPL/LimitedConcurrencyLevelTaskScheduler.cs b/src/NzbDrone.Common/TPL/LimitedConcurrencyLevelTaskScheduler.cs index f4614831b..4c28feb67 100644 --- a/src/NzbDrone.Common/TPL/LimitedConcurrencyLevelTaskScheduler.cs +++ b/src/NzbDrone.Common/TPL/LimitedConcurrencyLevelTaskScheduler.cs @@ -19,7 +19,7 @@ namespace NzbDrone.Common.TPL private readonly int _maxDegreeOfParallelism; /// Whether the scheduler is currently processing work items. - private int _delegatesQueuedOrRunning = 0; // protected by lock(_tasks) + private int _delegatesQueuedOrRunning; // protected by lock(_tasks) /// /// Initializes an instance of the LimitedConcurrencyLevelTaskScheduler class with the diff --git a/src/NzbDrone.Core/Datastore/WhereBuilder.cs b/src/NzbDrone.Core/Datastore/WhereBuilder.cs index da94e20e1..eeac16727 100644 --- a/src/NzbDrone.Core/Datastore/WhereBuilder.cs +++ b/src/NzbDrone.Core/Datastore/WhereBuilder.cs @@ -15,9 +15,9 @@ namespace NzbDrone.Core.Datastore private const DbType EnumerableMultiParameter = (DbType)(-1); private readonly string _paramNamePrefix; - private readonly bool _requireConcreteValue = false; - private int _paramCount = 0; - private bool _gotConcreteValue = false; + private readonly bool _requireConcreteValue; + private int _paramCount; + private bool _gotConcreteValue; public WhereBuilder(Expression filter, bool requireConcreteValue, int seq) { diff --git a/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs b/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs index 1818c4a22..ac734fcce 100644 --- a/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs +++ b/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs @@ -33,8 +33,8 @@ namespace NzbDrone.Core.HealthCheck private readonly ICached _healthCheckResults; - private bool _hasRunHealthChecksAfterGracePeriod = false; - private bool _isRunningHealthChecksAfterGracePeriod = false; + private bool _hasRunHealthChecksAfterGracePeriod; + private bool _isRunningHealthChecksAfterGracePeriod; public HealthCheckService(IEnumerable healthChecks, IEventAggregator eventAggregator, diff --git a/src/NzbDrone.Core/Indexers/IndexerDefinition.cs b/src/NzbDrone.Core/Indexers/IndexerDefinition.cs index 637d7c6c6..ef30dc7fb 100644 --- a/src/NzbDrone.Core/Indexers/IndexerDefinition.cs +++ b/src/NzbDrone.Core/Indexers/IndexerDefinition.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Core.Indexers public bool SupportsRss { get; set; } public bool SupportsSearch { get; set; } public int Priority { get; set; } = 25; - public int SeasonSearchMaximumSingleEpisodeAge { get; set; } = 0; + public int SeasonSearchMaximumSingleEpisodeAge { get; set; } public override bool Enable => EnableRss || EnableAutomaticSearch || EnableInteractiveSearch; diff --git a/src/NzbDrone.Core/Indexers/TorrentRssParser.cs b/src/NzbDrone.Core/Indexers/TorrentRssParser.cs index 991f53c8a..712c23d39 100644 --- a/src/NzbDrone.Core/Indexers/TorrentRssParser.cs +++ b/src/NzbDrone.Core/Indexers/TorrentRssParser.cs @@ -11,7 +11,7 @@ namespace NzbDrone.Core.Indexers public class TorrentRssParser : RssParser { // Use to sum/calculate Peers as Leechers+Seeders - public bool CalculatePeersAsSum { get; set; } = false; + public bool CalculatePeersAsSum { get; set; } // Use the specified element name to determine the Infohash public string InfoHashElementName { get; set; } diff --git a/src/NzbDrone.Mono/Disk/ProcMountProvider.cs b/src/NzbDrone.Mono/Disk/ProcMountProvider.cs index 5900d203c..2cce7d8b6 100644 --- a/src/NzbDrone.Mono/Disk/ProcMountProvider.cs +++ b/src/NzbDrone.Mono/Disk/ProcMountProvider.cs @@ -27,7 +27,7 @@ namespace NzbDrone.Mono.Disk private static Dictionary _fileSystems; - private bool _hasLoggedProcMountFailure = false; + private bool _hasLoggedProcMountFailure; public ProcMountProvider(Logger logger) {