Fix JsonNode.ToString allocations (#85886)
authorPent Ploompuu <kaalikas@gmail.com>
Sun, 7 May 2023 22:29:39 +0000 (01:29 +0300)
committerGitHub <noreply@github.com>
Sun, 7 May 2023 22:29:39 +0000 (18:29 -0400)
src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonNode.To.cs

index 8299ce7..6928851 100644 (file)
@@ -21,7 +21,7 @@ namespace System.Text.Json.Nodes
                 WriteTo(writer, options);
             }
 
-            return JsonHelpers.Utf8GetString(output.WrittenMemory.ToArray());
+            return JsonHelpers.Utf8GetString(output.WrittenMemory.Span);
         }
 
         /// <summary>
@@ -51,7 +51,7 @@ namespace System.Text.Json.Nodes
                 WriteTo(writer);
             }
 
-            return JsonHelpers.Utf8GetString(output.WrittenMemory.ToArray());
+            return JsonHelpers.Utf8GetString(output.WrittenMemory.Span);
         }
 
         /// <summary>