Use const where appropriate

The value of a const field is computed at compile time and stored in the metadata, which improves run-time performance when it is compared to a static readonly field.
This commit is contained in:
Qstick 2023-01-09 21:36:04 -06:00
parent b4d8f0c311
commit 42e45f93ac
5 changed files with 12 additions and 14 deletions

View File

@ -183,8 +183,6 @@ dotnet_diagnostic.CA1720.severity = suggestion
dotnet_diagnostic.CA1721.severity = suggestion dotnet_diagnostic.CA1721.severity = suggestion
dotnet_diagnostic.CA1724.severity = suggestion dotnet_diagnostic.CA1724.severity = suggestion
dotnet_diagnostic.CA1725.severity = suggestion dotnet_diagnostic.CA1725.severity = suggestion
dotnet_diagnostic.CA1801.severity = suggestion
dotnet_diagnostic.CA1802.severity = suggestion
dotnet_diagnostic.CA1805.severity = suggestion dotnet_diagnostic.CA1805.severity = suggestion
dotnet_diagnostic.CA1806.severity = suggestion dotnet_diagnostic.CA1806.severity = suggestion
dotnet_diagnostic.CA1810.severity = suggestion dotnet_diagnostic.CA1810.severity = suggestion

View File

@ -14,7 +14,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileDeletionService
[TestFixture] [TestFixture]
public class DeleteEpisodeFileFixture : CoreTest<Core.MediaFiles.MediaFileDeletionService> public class DeleteEpisodeFileFixture : CoreTest<Core.MediaFiles.MediaFileDeletionService>
{ {
private static readonly string RootFolder = @"C:\Test\TV"; private const string ROOT_FOLDER = @"C:\Test\TV";
private Series _series; private Series _series;
private EpisodeFile _episodeFile; private EpisodeFile _episodeFile;
@ -22,7 +22,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileDeletionService
public void Setup() public void Setup()
{ {
_series = Builder<Series>.CreateNew() _series = Builder<Series>.CreateNew()
.With(s => s.Path = Path.Combine(RootFolder, "Series Title")) .With(s => s.Path = Path.Combine(ROOT_FOLDER, "Series Title"))
.Build(); .Build();
_episodeFile = Builder<EpisodeFile>.CreateNew() _episodeFile = Builder<EpisodeFile>.CreateNew()
@ -32,7 +32,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileDeletionService
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetParentFolder(_series.Path)) .Setup(s => s.GetParentFolder(_series.Path))
.Returns(RootFolder); .Returns(ROOT_FOLDER);
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetParentFolder(_episodeFile.Path)) .Setup(s => s.GetParentFolder(_episodeFile.Path))
@ -42,14 +42,14 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileDeletionService
private void GivenRootFolderExists() private void GivenRootFolderExists()
{ {
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(RootFolder)) .Setup(s => s.FolderExists(ROOT_FOLDER))
.Returns(true); .Returns(true);
} }
private void GivenRootFolderHasFolders() private void GivenRootFolderHasFolders()
{ {
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectories(RootFolder)) .Setup(s => s.GetDirectories(ROOT_FOLDER))
.Returns(new[] { _series.Path }); .Returns(new[] { _series.Path });
} }

View File

@ -23,14 +23,14 @@ namespace NzbDrone.Core.Authentication
public class UserService : IUserService, IHandle<ApplicationStartedEvent> public class UserService : IUserService, IHandle<ApplicationStartedEvent>
{ {
private const int ITERATIONS = 10000;
private const int SALT_SIZE = 128 / 8;
private const int NUMBER_OF_BYTES = 256 / 8;
private readonly IUserRepository _repo; private readonly IUserRepository _repo;
private readonly IAppFolderInfo _appFolderInfo; private readonly IAppFolderInfo _appFolderInfo;
private readonly IDiskProvider _diskProvider; private readonly IDiskProvider _diskProvider;
private static readonly int ITERATIONS = 10000;
private static readonly int SALT_SIZE = 128 / 8;
private static readonly int NUMBER_OF_BYTES = 256 / 8;
public UserService(IUserRepository repo, IAppFolderInfo appFolderInfo, IDiskProvider diskProvider) public UserService(IUserRepository repo, IAppFolderInfo appFolderInfo, IDiskProvider diskProvider)
{ {
_repo = repo; _repo = repo;

View File

@ -13,7 +13,7 @@ namespace Sonarr.Http.ClientSchema
{ {
public static class SchemaBuilder public static class SchemaBuilder
{ {
private static readonly string PRIVATE_VALUE = "********"; private const string PRIVATE_VALUE = "********";
private static Dictionary<Type, FieldMapping[]> _mappings = new Dictionary<Type, FieldMapping[]>(); private static Dictionary<Type, FieldMapping[]> _mappings = new Dictionary<Type, FieldMapping[]>();
public static List<Field> ToSchema(object model) public static List<Field> ToSchema(object model)

View File

@ -12,9 +12,9 @@ namespace Sonarr.Http.Middleware
{ {
public class StartingUpMiddleware public class StartingUpMiddleware
{ {
private const string MESSAGE = "Sonarr is starting up, please try again later";
private readonly RequestDelegate _next; private readonly RequestDelegate _next;
private readonly IRuntimeInfo _runtimeInfo; private readonly IRuntimeInfo _runtimeInfo;
private static readonly string MESSAGE = "Sonarr is starting up, please try again later";
public StartingUpMiddleware(RequestDelegate next, IRuntimeInfo runtimeInfo) public StartingUpMiddleware(RequestDelegate next, IRuntimeInfo runtimeInfo)
{ {
@ -32,7 +32,7 @@ namespace Sonarr.Http.Middleware
context.Response.StatusCode = 503; context.Response.StatusCode = 503;
context.Response.ContentType = isJson ? "application/json" : "text/plain"; context.Response.ContentType = isJson ? "application/json" : "text/plain";
await context.Response.Body.WriteAsync(bytes, 0, bytes.Length); await context.Response.Body.WriteAsync(bytes);
return; return;
} }