Avoid unnecessary zero-length array allocations.
MODIFY
WalletWasabi.Gui/Dialogs/AvaloniaControlsExtensions.cs
WalletWasabi.Gui/Dialogs/AvaloniaControlsExtensions.cs
@@ -75,7 +75,7 @@ namespace Avalonia.Controls
}
else
{
- return new string[0];
+ return Array.Empty<string>();
}
}
}

MODIFY
WalletWasabi.Gui/ViewModels/Validation/ReflectionHelper.cs
WalletWasabi.Gui/ViewModels/Validation/ReflectionHelper.cs
@@ -36,7 +36,7 @@ namespace WalletWasabi.Gui.ViewModels.Validation
public static T InvokeMethod<T>(object instance, string methodName)
{
- MethodInfo info = instance.GetType().GetRuntimeMethod(methodName, new Type[0]);
+ MethodInfo info = instance.GetType().GetRuntimeMethod(methodName, Array.Empty<Type>());
if (info != null &&
info.ReturnType == typeof(T) &&
@@ -52,7 +52,7 @@ namespace WalletWasabi.Gui.ViewModels.Validation
public static MethodInfo GetMethodInfo<T>(object instance, string methodName)
{
- MethodInfo info = instance.GetType().GetRuntimeMethod(methodName, new Type[0]);
+ MethodInfo info = instance.GetType().GetRuntimeMethod(methodName, Array.Empty<Type>());
if (info != null &&
info.ReturnType == typeof(T) &&

MODIFY
WalletWasabi.Tests/UnitTests/IoTests.cs
WalletWasabi.Tests/UnitTests/IoTests.cs
@@ -196,7 +196,7 @@ namespace WalletWasabi.Tests.UnitTests
DigestableSafeMutexIoManager ioman = new DigestableSafeMutexIoManager(file);
ioman.DeleteMe();
- await ioman.WriteAllLinesAsync(new string[0]);
+ await ioman.WriteAllLinesAsync(Array.Empty<string>());
Assert.False(File.Exists(ioman.FilePath));
IoHelpers.EnsureContainingDirectoryExists(ioman.FilePath);
File.Create(ioman.FilePath).Dispose();

MODIFY
WalletWasabi/Backend/Models/FilterModel.cs
WalletWasabi/Backend/Models/FilterModel.cs
@@ -120,7 +120,7 @@ namespace WalletWasabi.Backend.Models
public byte[] ToBytes()
{
byte[] blockHashBytes = BlockHash.ToBytes();
- byte[] filterBytes = Filter is null ? new byte[0] : Filter.ToBytes();
+ byte[] filterBytes = Filter is null ? Array.Empty<byte>() : Filter.ToBytes();
byte[] filterLengthBytes = BitConverter.GetBytes(filterBytes.Length);
byte[] buffer = new byte[blockHashBytes.Length + filterLengthBytes.Length + filterBytes.Length];
Buffer.BlockCopy(blockHashBytes, 0, buffer, 0, blockHashBytes.Length);

MODIFY
WalletWasabi/Gma/QrCodeNet/Encoding/Positioning/Stencils/AlignmentPattern.cs
WalletWasabi/Gma/QrCodeNet/Encoding/Positioning/Stencils/AlignmentPattern.cs
@@ -58,7 +58,7 @@ namespace Gma.QrCodeNet.Encoding.Positioning.Stencils
private static byte[][] AlignmentPatternCoordinatesByVersion { get; } = new[]
{
null,
- new byte[] { },
+ System.Array.Empty<byte>(),
new byte[] { 6, 18},
new byte[] { 6, 22 },
new byte[] { 6, 26 },

MODIFY
WalletWasabi/Helpers/ByteHelpers.cs
WalletWasabi/Helpers/ByteHelpers.cs
@@ -147,7 +147,7 @@ namespace System
if (string.IsNullOrWhiteSpace(hex))
{
- return new byte[0];
+ return Array.Empty<byte>();
}
var bytes = new byte[hex.Length / 2];

MODIFY
WalletWasabi/Helpers/HttpMessageHelper.cs
WalletWasabi/Helpers/HttpMessageHelper.cs
@@ -532,7 +532,7 @@ namespace System.Net.Http
{
if (contentHeaders.NotNullAndNotEmpty())
{
- return new byte[] { }; // dummy empty content
+ return Array.Empty<byte>(); // dummy empty content
}
return null;
}

MODIFY
WalletWasabi/Http/Models/HeaderSection.cs
WalletWasabi/Http/Models/HeaderSection.cs
@@ -126,7 +126,7 @@ namespace WalletWasabi.Http.Models
{
using var message = new HttpRequestMessage
{
- Content = new ByteArrayContent(new byte[] { })
+ Content = new ByteArrayContent(Array.Empty<byte>())
};
message.Content.Headers.ContentLength = null;
foreach (var field in Fields)
@@ -152,7 +152,7 @@ namespace WalletWasabi.Http.Models
{
using var message = new HttpResponseMessage
{
- Content = new ByteArrayContent(new byte[] { })
+ Content = new ByteArrayContent(Array.Empty<byte>())
};
message.Content.Headers.ContentLength = null;
foreach (var field in Fields)

MODIFY
WalletWasabi/Models/ChaumianCoinJoin/Alice.cs
WalletWasabi/Models/ChaumianCoinJoin/Alice.cs
@@ -32,7 +32,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
Inputs = Guard.NotNullOrEmpty(nameof(inputs), inputs);
NetworkFeeToPayAfterBaseDenomination = Guard.NotNull(nameof(networkFeeToPayAfterBaseDenomination), networkFeeToPayAfterBaseDenomination);
- BlindedOutputScripts = blindedOutputScripts?.ToArray() ?? new uint256[0];
+ BlindedOutputScripts = blindedOutputScripts?.ToArray() ?? Array.Empty<uint256>();
ChangeOutputAddress = Guard.NotNull(nameof(changeOutputAddress), changeOutputAddress);
LastSeen = DateTimeOffset.UtcNow;
@@ -43,7 +43,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
State = AliceState.InputsRegistered;
- BlindedOutputSignatures = new uint256[0];
+ BlindedOutputSignatures = Array.Empty<uint256>();
}
}
}

MODIFY
WalletWasabi/Models/SmartLabel.cs
WalletWasabi/Models/SmartLabel.cs
@@ -23,7 +23,7 @@ namespace WalletWasabi.Models
{
labels ??= Enumerable.Empty<string>();
Labels = labels
- .SelectMany(x => x?.Split(Separators, StringSplitOptions.RemoveEmptyEntries) ?? new string[0])
+ .SelectMany(x => x?.Split(Separators, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>())
.Select(x => x.Trim())
.Where(x => x != "")
.Distinct(StringComparer.OrdinalIgnoreCase)

MODIFY
WalletWasabi/Mono/HelpCommand.cs
WalletWasabi/Mono/HelpCommand.cs
@@ -171,7 +171,7 @@ namespace Mono.Options
public override async Task<int> InvokeAsync(IEnumerable<string> arguments)
{
- var extra = new List<string>(arguments ?? new string[0]);
+ var extra = new List<string>(arguments ?? Array.Empty<string>());
if (extra.Count == 0)
{
CommandSet.Options.WriteOptionDescriptions(CommandSet.Out);

MODIFY
WalletWasabi/Mono/Option.cs
WalletWasabi/Mono/Option.cs
@@ -248,7 +248,7 @@ namespace Mono.Options
{
if (ValueSeparators is null)
{
- return new string[0];
+ return Array.Empty<string>();
}
return (string[])ValueSeparators.Clone();

MODIFY
WalletWasabi/TorSocks5/TorHttpClient.cs
WalletWasabi/TorSocks5/TorHttpClient.cs
@@ -243,7 +243,7 @@ namespace WalletWasabi.TorSocks5
{
if (request.Content is null)
{
- request.Content = new ByteArrayContent(new byte[] { }); // dummy empty content
+ request.Content = new ByteArrayContent(Array.Empty<byte>()); // dummy empty content
request.Content.Headers.ContentLength = 0;
}
else

Avoid unnecessary zero-length array allocations.