Apply minor performance rules

This commit is contained in:
Huo Yaoyuan 2024-11-28 20:37:53 +08:00
parent 13d7c6a2d8
commit f5a7716509
14 changed files with 34 additions and 24 deletions

View File

@ -50,6 +50,22 @@ dotnet_diagnostic.IDE1006.severity = warning
# Too many noisy warnings for parsing/formatting numbers
dotnet_diagnostic.CA1305.severity = none
# CA1806: Do not ignore method results
# The usages for numeric parsing are explicitly optional
dotnet_diagnostic.CA1806.severity = suggestion
# CA1822: Mark members as static
# Potential false positive around reflection/too much noise
dotnet_diagnostic.CA1822.severity = none
# CA1859: Use concrete types when possible for improved performance
# Involves design considerations
dotnet_diagnostic.CA1859.severity = none
# CA1861: Avoid constant arrays as arguments
# Outdated with collection expressions
dotnet_diagnostic.CA1861.severity = none
# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = warning

View File

@ -27,6 +27,7 @@
<AnalysisModeInteroperability>Recommended</AnalysisModeInteroperability>
<AnalysisModeMaintainability>Recommended</AnalysisModeMaintainability>
<AnalysisModeNaming>Default</AnalysisModeNaming>
<AnalysisModePerformance>Minimum</AnalysisModePerformance>
</PropertyGroup>
<PropertyGroup Label="Documentation">
<GenerateDocumentationFile>true</GenerateDocumentationFile>

View File

@ -198,7 +198,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("make second user host", () => MultiplayerClient.TransferHost(3));
AddUntilStep("kick buttons not visible", () => this.ChildrenOfType<ParticipantPanel.KickButton>().Count(d => d.IsPresent) == 0);
AddUntilStep("kick buttons not visible", () => !this.ChildrenOfType<ParticipantPanel.KickButton>().Any(d => d.IsPresent));
AddStep("make local user host again", () => MultiplayerClient.TransferHost(API.LocalUser.Value.Id));

View File

@ -151,7 +151,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("click delete option", () =>
{
InputManager.MoveMouseTo(contextMenuContainer.ChildrenOfType<DrawableOsuMenuItem>().First(i => i.Item.Text.Value.ToString().ToLowerInvariant() == "delete"));
InputManager.MoveMouseTo(contextMenuContainer.ChildrenOfType<DrawableOsuMenuItem>().First(i => string.Equals(i.Item.Text.Value.ToString(), "delete", System.StringComparison.OrdinalIgnoreCase)));
InputManager.Click(MouseButton.Left);
});

View File

@ -60,7 +60,7 @@ namespace osu.Game.Extensions
public static string ToCamelCase(this string input)
{
string word = input.ToPascalCase();
return word.Length > 0 ? word.Substring(0, 1).ToLowerInvariant() + word.Substring(1) : word;
return word.Length > 0 ? char.ToLowerInvariant(word[0]) + word.Substring(1) : word;
}
/// <summary>

View File

@ -120,10 +120,9 @@ namespace osu.Game.Overlays.Chat.ChannelList
public void RemoveChannel(Channel channel)
{
if (!channelMap.ContainsKey(channel))
if (!channelMap.TryGetValue(channel, out var item))
return;
ChannelListItem item = channelMap[channel];
FillFlowContainer<ChannelListItem> flow = getFlowForChannel(channel);
channelMap.Remove(channel);
@ -132,13 +131,7 @@ namespace osu.Game.Overlays.Chat.ChannelList
updateVisibility();
}
public ChannelListItem GetItem(Channel channel)
{
if (!channelMap.ContainsKey(channel))
throw new ArgumentOutOfRangeException();
return channelMap[channel];
}
public ChannelListItem GetItem(Channel channel) => channelMap[channel];
public void ScrollChannelIntoView(Channel channel) => scroll.ScrollIntoView(GetItem(channel));

View File

@ -386,9 +386,8 @@ namespace osu.Game.Overlays
{
channelList.RemoveChannel(channel);
if (loadedChannels.ContainsKey(channel))
if (loadedChannels.TryGetValue(channel, out var loaded))
{
DrawableChannel loaded = loadedChannels[channel];
loadedChannels.Remove(channel);
// DrawableChannel removed from cache must be manually disposed
loaded.Dispose();

View File

@ -244,7 +244,7 @@ namespace osu.Game.Overlays.Comments
protected void OnSuccess(CommentBundle response)
{
commentCounter.Current.Value = response.Total;
newCommentEditor.CommentableMeta.Value = response.CommentableMeta.SingleOrDefault(m => m.Id == id.Value && m.Type == type.Value.ToString().ToSnakeCase().ToLowerInvariant());
newCommentEditor.CommentableMeta.Value = response.CommentableMeta.SingleOrDefault(m => m.Id == id.Value && string.Equals(m.Type, type.Value.ToString().ToSnakeCase(), StringComparison.OrdinalIgnoreCase));
if (!response.Comments.Any())
{

View File

@ -173,10 +173,10 @@ namespace osu.Game.Rulesets.Mods
};
drawable.OnRevertResult += (_, result) =>
{
if (!ratesForRewinding.ContainsKey(result.HitObject)) return;
if (!ratesForRewinding.TryGetValue(result.HitObject, out double rewindValue)) return;
if (!shouldProcessResult(result)) return;
recentRates.Insert(0, ratesForRewinding[result.HitObject]);
recentRates.Insert(0, rewindValue);
ratesForRewinding.Remove(result.HitObject);
recentRates.RemoveAt(recentRates.Count - 1);

View File

@ -243,7 +243,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
return PathType.CATMULL;
case 'B':
if (input.Length > 1 && int.TryParse(input.Substring(1), out int degree) && degree > 0)
if (input.Length > 1 && int.TryParse(input.AsSpan(1), out int degree) && degree > 0)
return PathType.BSpline(degree);
return PathType.BEZIER;

View File

@ -59,14 +59,14 @@ namespace osu.Game.Screens.Ranking.Statistics.User
new SimpleStatisticTable.Spacer(),
new PerformancePointsChangeRow { StatisticsUpdate = { BindTarget = StatisticsUpdate } },
},
new Drawable[] { },
[],
new Drawable[]
{
new MaximumComboChangeRow { StatisticsUpdate = { BindTarget = StatisticsUpdate } },
new SimpleStatisticTable.Spacer(),
new AccuracyChangeRow { StatisticsUpdate = { BindTarget = StatisticsUpdate } },
},
new Drawable[] { },
[],
new Drawable[]
{
new RankedScoreChangeRow { StatisticsUpdate = { BindTarget = StatisticsUpdate } },

View File

@ -37,7 +37,7 @@ namespace osu.Game.Skinning
protected override string[] HashableFileTypes => new[] { ".ini", ".json" };
protected override bool ShouldDeleteArchive(string path) => Path.GetExtension(path).ToLowerInvariant() == @".osk";
protected override bool ShouldDeleteArchive(string path) => string.Equals(Path.GetExtension(path), @".osk", StringComparison.OrdinalIgnoreCase);
protected override SkinInfo CreateModel(ArchiveReader archive, ImportParameters parameters) => new SkinInfo { Name = archive.Name ?? @"No name" };

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -89,7 +90,7 @@ namespace osu.Game.Storyboards
// Importantly, do this after the NullOrEmpty because EF may have stored the non-nullable value as null to the database, bypassing compile-time constraints.
backgroundPath = backgroundPath.ToLowerInvariant();
return GetLayer("Background").Elements.Any(e => e.Path.ToLowerInvariant() == backgroundPath);
return GetLayer("Background").Elements.Any(e => string.Equals(e.Path, backgroundPath, StringComparison.OrdinalIgnoreCase));
}
}

View File

@ -78,12 +78,12 @@ namespace osu.Game.Tests.Visual.Spectator
/// <param name="state">The spectator state to end play with.</param>
public void SendEndPlay(int userId, SpectatedUserState state = SpectatedUserState.Quit)
{
if (!userBeatmapDictionary.ContainsKey(userId))
if (!userBeatmapDictionary.TryGetValue(userId, out int beatmapId))
return;
((ISpectatorClient)this).UserFinishedPlaying(userId, new SpectatorState
{
BeatmapID = userBeatmapDictionary[userId],
BeatmapID = beatmapId,
RulesetID = 0,
Mods = userModsDictionary[userId],
State = state