Skip to content

Commit

Permalink
Remove unnecessary char[] allocation from Uri.GetRelativeSerializatio…
Browse files Browse the repository at this point in the history
…nString (dotnet#54799)
  • Loading branch information
stephentoub authored Jun 28, 2021
1 parent 6fdb82a commit 985eb81
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/libraries/System.Private.Uri/src/System/UriExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,11 +744,9 @@ private unsafe string GetRelativeSerializationString(UriFormat format)
if (_string.Length == 0)
return string.Empty;

char[] dest = new char[_string.Length];
int position = 0;
dest = UriHelper.UnescapeString(_string, 0, _string.Length, dest, ref position, c_DummyChar,
c_DummyChar, c_DummyChar, UnescapeMode.EscapeUnescape, null, false);
return new string(dest, 0, position);
var vsb = new ValueStringBuilder(stackalloc char[StackallocThreshold]);
UriHelper.UnescapeString(_string, ref vsb, c_DummyChar, c_DummyChar, c_DummyChar, UnescapeMode.EscapeUnescape, null, false);
return vsb.ToString();
}
else
{
Expand Down

0 comments on commit 985eb81

Please sign in to comment.