From 8b223f2403961ef41336346e7c9ff515b11da7e8 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 --- .../shared/System/Text/ValueStringBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs b/src/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs index b62140b968b4..c7563cb62f4d 100644 --- a/src/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs @@ -286,7 +286,7 @@ private void Grow(int additionalCapacityBeyondPos) 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;