Skip to content

Commit

Permalink
Remove char[] allocation from XmlConverter.StripWhitespace (#32297)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Feb 15, 2020
1 parent 3ef2c11 commit 9fedc93
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1146,17 +1146,19 @@ public static string StripWhitespace(string s)
}
if (count == s.Length)
return s;
char[] chars = new char[count];
count = 0;
for (int i = 0; i < s.Length; i++)

return string.Create(count, s, (chars, s) =>
{
char ch = s[i];
if (!IsWhitespace(ch))
int count = 0;
for (int i = 0; i < s.Length; i++)
{
chars[count++] = ch;
char ch = s[i];
if (!IsWhitespace(ch))
{
chars[count++] = ch;
}
}
}
return new string(chars);
});
}

private static string Trim(string s)
Expand Down

0 comments on commit 9fedc93

Please sign in to comment.