HttpClient: Faster whitespace detection

Instead of allocating a List<char> with the four allowed whitespace
chars and searching the list, just check if the char is one of the
four values.


Commit migrated from https://github.com/dotnet/corefx/commit/bcc05791de64688b681e01974a0ba8f7d75f2501
This commit is contained in:
Justin Van Patten committed 2016-08-06 19:36:27 -07:00
1 parent e586f359b1
commit d023bc99bd
2 files changed
+7 -13

No files matched your search

@@ -223,7 +223,7 @@ namespace System.Net.Mail
// before the next address.
if (index >= 0 &&
!(
MailBnfHelper.Whitespace.Contains(data[index]) // < local@domain >
MailBnfHelper.IsAllowedWhiteSpace(data[index]) // < local@domain >
|| data[index] == MailBnfHelper.EndComment // <(comment)local@domain>
|| (expectAngleBracket && data[index] == MailBnfHelper.StartAngleBracket) // <local@domain>
|| (expectMultipleAddresses && data[index] == MailBnfHelper.Comma) // local@dom,local@dom
@@ -47,18 +47,6 @@ namespace System.Net.Mime
internal static readonly char EndSquareBracket = ']';
internal static readonly char Comma = ',';
internal static readonly char Dot = '.';
internal static readonly IList<char> Whitespace = CreateAllowedWhitespace();
private static List<char> CreateAllowedWhitespace()
{
// all allowed whitespace characters
var whitespace = new List<char>(4);
whitespace.Add(Tab);
whitespace.Add(Space);
whitespace.Add(CR);
whitespace.Add(LF);
return whitespace;
}
// NOTE: See RFC 2822 for more detail. By default, every value in the array is false and only
// those values which are allowed in that particular set are then set to true. The numbers
@@ -397,6 +385,12 @@ namespace System.Net.Mime
return true;
}
internal static bool IsAllowedWhiteSpace(char c)
{
// all allowed whitespace characters
return c == Tab || c == Space || c == CR || c == LF;
}
internal static bool HasCROrLF(string data)
{
for (int i = 0; i < data.Length; i++)