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.
pull/5493/head
Qstick 1 year ago
parent b4d8f0c311
commit 42e45f93ac

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

@ -14,7 +14,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileDeletionService
[TestFixture]
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 EpisodeFile _episodeFile;
@ -22,7 +22,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileDeletionService
public void Setup()
{
_series = Builder<Series>.CreateNew()
.With(s => s.Path = Path.Combine(RootFolder, "Series Title"))
.With(s => s.Path = Path.Combine(ROOT_FOLDER, "Series Title"))
.Build();
_episodeFile = Builder<EpisodeFile>.CreateNew()
@ -32,7 +32,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileDeletionService
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetParentFolder(_series.Path))
.Returns(RootFolder);
.Returns(ROOT_FOLDER);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetParentFolder(_episodeFile.Path))
@ -42,14 +42,14 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileDeletionService
private void GivenRootFolderExists()
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(RootFolder))
.Setup(s => s.FolderExists(ROOT_FOLDER))
.Returns(true);
}
private void GivenRootFolderHasFolders()
{
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectories(RootFolder))
.Setup(s => s.GetDirectories(ROOT_FOLDER))
.Returns(new[] { _series.Path });
}

@ -23,14 +23,14 @@ namespace NzbDrone.Core.Authentication
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 IAppFolderInfo _appFolderInfo;
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)
{
_repo = repo;

@ -13,7 +13,7 @@ namespace Sonarr.Http.ClientSchema
{
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[]>();
public static List<Field> ToSchema(object model)

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

Loading…
Cancel
Save