Optimise HtmlEncode to produce less garbage
authorBenjamin Hodgson <bhodgson@stackoverflow.com>
Mon, 19 Feb 2018 14:20:05 +0000 (14:20 +0000)
committerJan Kotas <jkotas@microsoft.com>
Mon, 4 Jun 2018 18:01:04 +0000 (11:01 -0700)
do the same optimisation for HtmlDecode

remove now-unneeded reference

Add tests for new ValueStringBuilder methods

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
src/System.Private.CoreLib/shared/System/Text/ValueStringBuilder.cs

index d41bea0..1e33bdb 100644 (file)
@@ -22,6 +22,13 @@ namespace System.Text
             _pos = 0;
         }
 
+        public ValueStringBuilder(int initialCapacity)
+        {
+            _arrayToReturnToPool = ArrayPool<char>.Shared.Rent(initialCapacity);
+            _chars = _arrayToReturnToPool;
+            _pos = 0;
+        }
+
         public int Length
         {
             get => _pos;