Speed up some empty array checks
MODIFY
WalletWasabi/Helpers/Guard.cs
WalletWasabi/Helpers/Guard.cs
@@ -25,12 +25,12 @@ namespace WalletWasabi.Helpers
throw new ArgumentNullException(nameof(parameterName), "Parameter cannot be null.");
}
- if (parameterName == "")
+ if (parameterName.Length == 0)
{
throw new ArgumentException("Parameter cannot be empty.", nameof(parameterName));
}
- if (parameterName.Trim() == "")
+ if (parameterName.Trim().Length == 0)
{
throw new ArgumentException("Parameter cannot be whitespace.", nameof(parameterName));
}
@@ -98,7 +98,7 @@ namespace WalletWasabi.Helpers
NotNullOrEmpty(parameterName, value);
string trimmedValue = value.Trim();
- if (trimmedValue == "")
+ if (trimmedValue.Length == 0)
{
throw new ArgumentException("Parameter cannot be whitespace.", parameterName);
}

MODIFY
WalletWasabi/Helpers/HttpMessageHelper.cs
WalletWasabi/Helpers/HttpMessageHelper.cs
@@ -61,7 +61,7 @@ namespace System.Net.Http
throw new FormatException("Malformed HTTP message: End of headers must be CRLF.");
}
- if (header == "")
+ if (header.Length == 0)
{
// 2 CRLF was read in row so it's the end of the headers
break;
@@ -338,7 +338,8 @@ namespace System.Net.Http
while (chunkSize > 0)
{
var chunkData = await ReadBytesTillLengthAsync(stream, chunkSize, ctsToken);
- if (await ReadCRLFLineAsync(stream, Encoding.ASCII, ctsToken) != "")
+ string crlfLine = await ReadCRLFLineAsync(stream, Encoding.ASCII, ctsToken);
+ if (crlfLine.Length == 0)
{
throw new FormatException("Chunk does not end with CRLF.");
}

MODIFY
WalletWasabi/Helpers/HttpRequestUriBuilder.cs
WalletWasabi/Helpers/HttpRequestUriBuilder.cs
@@ -18,7 +18,7 @@ namespace System.Net.Http
var h = host.Trim().TrimEnd('/').TrimStart(uriScheme.ToString() + "://", StringComparison.OrdinalIgnoreCase);
// https://tools.ietf.org/html/rfc7230#section-2.7.1
// A sender MUST NOT generate an "http" URI with an empty host identifier.
- if (h == "")
+ if (h.Length == 0)
{
throw new FormatException("Host identifier is empty.");
}

Speed up some empty array checks