Skip to content

Commit

Permalink
Improve some String.Split calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
RoosterDragon authored and penev92 committed Nov 15, 2024
1 parent cf7f572 commit bf7f81b
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion OpenRA.Game/Scripting/ScriptMemberWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static string[] RequiredTraitNames(Type t)

// Remove the namespace and the trailing "Info"
return types.SelectMany(i => i.GetGenericArguments())
.Select(g => g.Name.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault())
.Select(g => g.Name.Split('.', StringSplitOptions.RemoveEmptyEntries).LastOrDefault())
.Select(s => s.EndsWith("Info", StringComparison.Ordinal) ? s.Remove(s.Length - 4, 4) : s)
.ToArray();
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Traits/World/VoxelCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ IModel LoadVoxel(string unit, MiniYaml info)
var hva = unit;
if (info.Value != null)
{
var fields = info.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var fields = info.Value.Split(',', StringSplitOptions.RemoveEmptyEntries);
if (fields.Length >= 1)
vxl = hva = fields[0].Trim();

Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/UtilityCommands/Rgba2Hex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sealed class Rgba2Hex : IUtilityCommand
{
string IUtilityCommand.Name => "--rgba2hex";

static readonly char[] Comma = new char[] { ',' };
const char Comma = ',';

bool IUtilityCommand.ValidateArguments(string[] args)
{
Expand Down Expand Up @@ -105,7 +105,7 @@ sealed class Argb2Hex : IUtilityCommand
{
string IUtilityCommand.Name => "--argb2hex";

static readonly char[] Comma = new char[] { ',' };
const char Comma = ',';

bool IUtilityCommand.ValidateArguments(string[] args)
{
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Widgets/LabelWithHighlightWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected LabelWithHighlightWidget(LabelWithHighlightWidget other)
(string, bool)[] MakeComponents(string text)
{
var components = new List<(string, bool)>();
foreach (var l in text.Split(new[] { "\\n" }, StringSplitOptions.None))
foreach (var l in text.Split("\\n", StringSplitOptions.None))
{
var line = l;

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Widgets/Logic/ButtonTooltipLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ButtonTooltipLogic(Widget widget, ButtonWidget button)
var descFont = Game.Renderer.Fonts[descTemplate.Font];
var descWidth = 0;
var descOffset = descTemplate.Bounds.Y;
foreach (var line in desc.Split(new[] { "\n" }, StringSplitOptions.None))
foreach (var line in desc.Split('\n', StringSplitOptions.None))
{
descWidth = Math.Max(descWidth, descFont.Measure(line).X);
var lineLabel = (LabelWidget)descTemplate.Clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void DownloadUrl(string url)
var httpResponseMessage = await client.GetAsync(download.MirrorList);
var result = await httpResponseMessage.Content.ReadAsStringAsync();

var mirrorList = result.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
var mirrorList = result.Split('\n', StringSplitOptions.RemoveEmptyEntries);
DownloadUrl(mirrorList.Random(new MersenneTwister()));
}
catch (Exception e)
Expand Down

0 comments on commit bf7f81b

Please sign in to comment.