Skip to content

Commit

Permalink
Remove excess allocations in Uri.ReCreateParts (#34864)
Browse files Browse the repository at this point in the history
* Remove excess allocations in Uri.ReCreateParts

* Fix Compression offset

* Revert VSB optimizations

* Use noEscape.Length

* Simplify TryGetUnicodeEquivalent

* Remove ValueStringBuilderExtensions

* Index into chars instead of dest

* Remove unreachable code block

* Use StackallocThreshold constant

* Add comments about why MemoryMarshal is used to recreate the span
  • Loading branch information
MihaZupan authored Jan 22, 2021
1 parent f1ad1b9 commit 39d72d4
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 296 deletions.
4 changes: 2 additions & 2 deletions src/libraries/System.Private.Uri/src/System/IriHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ internal static bool CheckIsReserved(char ch, UriComponents component)
internal static unsafe string EscapeUnescapeIri(char* pInput, int start, int end, UriComponents component)
{
int size = end - start;
ValueStringBuilder dest = size <= 256
? new ValueStringBuilder(stackalloc char[256])
var dest = size <= Uri.StackallocThreshold
? new ValueStringBuilder(stackalloc char[Uri.StackallocThreshold])
: new ValueStringBuilder(size);

Span<byte> maxUtf8EncodedSpan = stackalloc byte[4];
Expand Down
Loading

0 comments on commit 39d72d4

Please sign in to comment.