From 6ae336034290d14825ab8acb4b0385b9d69fa48a Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Wed, 30 Oct 2019 20:00:25 -0400 Subject: [PATCH] Clean up Uri.UnescapeDataString (dotnet/corefx#42225) - Use string.IndexOf rather than an open-coded, unsafe loop. - Avoid an unnecessary SequenceEquals at the end: we're only at this point if a `%` was found highlighting that something escaped was found. - Use stack memory for smaller inputs if possible, to avoid unnecessary ArrayPool interaction - Remove an unnecessary argument to a helper function. - Fix ValueStringBuilder.Grow to only copy the contained data. Signed-off-by: dotnet-bot --- netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs b/netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs index b62140b968b..c7563cb62f4 100644 --- a/netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs +++ b/netcore/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs @@ -286,7 +286,7 @@ namespace System.Text char[] poolArray = ArrayPool.Shared.Rent(Math.Max(_pos + additionalCapacityBeyondPos, _chars.Length * 2)); - _chars.CopyTo(poolArray); + _chars.Slice(0, _pos).CopyTo(poolArray); char[]? toReturn = _arrayToReturnToPool; _chars = _arrayToReturnToPool = poolArray; -- 2.11.4.GIT