diff --git a/src/libraries/Common/src/Polyfills/SkipLocalsInitAttributePolyfill.cs b/src/libraries/Common/src/Polyfills/SkipLocalsInitAttributePolyfill.cs
new file mode 100644
index 00000000000000..e7f24c49466e85
--- /dev/null
+++ b/src/libraries/Common/src/Polyfills/SkipLocalsInitAttributePolyfill.cs
@@ -0,0 +1,27 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+namespace System.Runtime.CompilerServices;
+
+///
+/// Used to indicate to the compiler that the .locals init flag should not be set in method headers.
+///
+///
+/// Downlevel polyfill of System.Runtime.CompilerServices.SkipLocalsInitAttribute
+/// for target frameworks that do not provide it (.NET Standard 2.0, .NET Framework). The C# compiler recognizes the
+/// attribute by full type name, so providing this internal definition is enough to enable the optimization.
+///
+[AttributeUsage(AttributeTargets.Module
+ | AttributeTargets.Class
+ | AttributeTargets.Struct
+ | AttributeTargets.Interface
+ | AttributeTargets.Constructor
+ | AttributeTargets.Method
+ | AttributeTargets.Property
+ | AttributeTargets.Event, Inherited = false)]
+internal sealed class SkipLocalsInitAttribute : Attribute
+{
+ public SkipLocalsInitAttribute()
+ {
+ }
+}
diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj
index 2f1a903683e201..2d9b8f0d0a3b55 100644
--- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj
+++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj
@@ -13,6 +13,9 @@
The System.Text.Json library is built-in as part of the shared framework in .NET Runtime. The package can be installed when you need to use it in other target frameworks.
true
+
+ false
@@ -402,6 +405,7 @@ The System.Text.Json library is built-in as part of the shared framework in .NET
+
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.TryGetProperty.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.TryGetProperty.cs
index 6445b14be512cb..544cf96bec5131 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.TryGetProperty.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.TryGetProperty.cs
@@ -3,11 +3,13 @@
using System.Buffers;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
public sealed partial class JsonDocument
{
+ [SkipLocalsInit]
internal unsafe bool TryGetNamedPropertyValue(int index, ReadOnlySpan propertyName, out JsonElement value)
{
CheckNotDisposed();
@@ -132,6 +134,7 @@ internal bool TryGetNamedPropertyValue(int index, ReadOnlySpan propertyNam
out value);
}
+ [SkipLocalsInit]
private unsafe bool TryGetNamedPropertyValue(
int startIndex,
int endIndex,
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs
index 185df75c8bd5aa..d48cc3901e18f7 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs
@@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
using System.Threading;
namespace System.Text.Json
@@ -302,6 +303,7 @@ private ReadOnlyMemory GetPropertyRawValue(int valueIndex)
: JsonReaderHelper.TranscodeHelper(segment);
}
+ [SkipLocalsInit]
internal unsafe bool TextEquals(int index, ReadOnlySpan otherText, bool isPropertyName)
{
CheckNotDisposed();
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/JsonEncodedText.cs b/src/libraries/System.Text.Json/src/System/Text/Json/JsonEncodedText.cs
index cc2e05ac1291b1..42951a87924a87 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/JsonEncodedText.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/JsonEncodedText.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
using System.Text.Encodings.Web;
namespace System.Text.Json
@@ -73,6 +74,7 @@ public static JsonEncodedText Encode(ReadOnlySpan value, JavaScriptEncoder
return TranscodeAndEncode(value, encoder);
}
+ [SkipLocalsInit]
private static unsafe JsonEncodedText TranscodeAndEncode(ReadOnlySpan value, JavaScriptEncoder? encoder)
{
JsonWriterHelper.ValidateValue(value);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Escaping.cs b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Escaping.cs
index c719c1f0b53d75..e80c8ec883d9cb 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Escaping.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Escaping.cs
@@ -25,6 +25,7 @@ public static byte[] GetEscapedPropertyNameSection(ReadOnlySpan utf8Value,
}
}
+ [SkipLocalsInit]
public static unsafe byte[] EscapeValue(
ReadOnlySpan utf8Value,
int firstEscapeIndexVal,
@@ -53,6 +54,7 @@ public static unsafe byte[] EscapeValue(
return escapedString;
}
+ [SkipLocalsInit]
private static unsafe byte[] GetEscapedPropertyNameSection(
ReadOnlySpan utf8Value,
int firstEscapeIndexVal,
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs
index 15743c819e716a..532fa3d4a9c19a 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs
@@ -190,6 +190,7 @@ public static bool TrySkipPartial(this ref Utf8JsonReader reader)
return reader.TrySkipPartial(reader.CurrentDepth);
}
+ [SkipLocalsInit]
public static unsafe bool TryLookupUtf8Key(
this Dictionary dictionary,
ReadOnlySpan utf8Key,
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs
index 3c3bdbf682a434..21dfd9dc575337 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonArray.cs
@@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
using System.Text.Json.Serialization.Converters;
using System.Threading;
@@ -238,6 +239,7 @@ private protected override void SetItem(int index, JsonNode? value)
List[index] = value;
}
+ [SkipLocalsInit]
internal override unsafe void GetPath(ref ValueStringBuilder path, JsonNode? child)
{
Parent?.GetPath(ref path, this);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonNode.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonNode.cs
index 76d1fd906f6662..4d93b66058cada 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonNode.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonNode.cs
@@ -1,9 +1,10 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
using System.Text.Json.Serialization.Converters;
using System.Text.Json.Serialization.Metadata;
@@ -135,6 +136,7 @@ internal set
/// Gets the JSON path.
///
/// The JSON Path value.
+ [SkipLocalsInit]
public unsafe string GetPath()
{
if (Parent == null)
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.Unescaping.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.Unescaping.cs
index f5d37b2e3d36a2..4f57d8960bbf0d 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.Unescaping.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.Unescaping.cs
@@ -5,12 +5,14 @@
using System.Buffers.Text;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
using System.Text.Unicode;
namespace System.Text.Json
{
internal static partial class JsonReaderHelper
{
+ [SkipLocalsInit]
public static unsafe bool TryGetUnescapedBase64Bytes(ReadOnlySpan utf8Source, [NotNullWhen(true)] out byte[]? bytes)
{
byte[]? unescapedArray = null;
@@ -39,6 +41,7 @@ public static unsafe bool TryGetUnescapedBase64Bytes(ReadOnlySpan utf8Sour
public static readonly UTF8Encoding s_utf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
// TODO: Similar to escaping, replace the unescaping logic with publicly shipping APIs from https://github.com/dotnet/runtime/issues/27919
+ [SkipLocalsInit]
public static unsafe string GetUnescapedString(ReadOnlySpan utf8Source)
{
// The escaped name is always >= than the unescaped, so it is safe to use escaped name for the buffer length.
@@ -66,6 +69,7 @@ public static unsafe string GetUnescapedString(ReadOnlySpan utf8Source)
return utf8String;
}
+ [SkipLocalsInit]
public static unsafe byte[] GetUnescaped(ReadOnlySpan utf8Source)
{
// The escaped name is always >= than the unescaped, so it is safe to use escaped name for the buffer length.
@@ -91,6 +95,7 @@ public static unsafe byte[] GetUnescaped(ReadOnlySpan utf8Source)
return propertyName;
}
+ [SkipLocalsInit]
public static unsafe bool UnescapeAndCompare(ReadOnlySpan utf8Source, ReadOnlySpan other)
{
Debug.Assert(utf8Source.Length >= other.Length && utf8Source.Length / JsonConstants.MaxExpansionFactorWhileEscaping <= other.Length);
@@ -118,6 +123,7 @@ public static unsafe bool UnescapeAndCompare(ReadOnlySpan utf8Source, Read
return result;
}
+ [SkipLocalsInit]
public static unsafe bool UnescapeAndCompare(ReadOnlySequence utf8Source, ReadOnlySpan other)
{
Debug.Assert(!utf8Source.IsSingleSegment);
@@ -159,6 +165,7 @@ public static unsafe bool UnescapeAndCompare(ReadOnlySequence utf8Source,
return result;
}
+ [SkipLocalsInit]
public static unsafe bool UnescapeAndCompareBothInputs(ReadOnlySpan utf8Source1, ReadOnlySpan utf8Source2)
{
int index1 = utf8Source1.IndexOf(JsonConstants.BackSlash);
@@ -215,6 +222,7 @@ public static bool TryDecodeBase64InPlace(Span utf8Unescaped, [NotNullWhen
return true;
}
+ [SkipLocalsInit]
public static unsafe bool TryDecodeBase64(ReadOnlySpan utf8Unescaped, [NotNullWhen(true)] out byte[]? bytes)
{
byte[]? pooledArray = null;
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs
index 50e684b71b3613..deac1da047d030 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs
@@ -176,6 +176,7 @@ public static bool TryGetValue(ReadOnlySpan segment, bool isEscaped, out D
return false;
}
+ [SkipLocalsInit]
public static unsafe bool TryGetEscapedDateTime(ReadOnlySpan source, out DateTime value)
{
Debug.Assert(source.Length <= JsonConstants.MaximumEscapedDateTimeOffsetParseLength);
@@ -224,6 +225,7 @@ public static bool TryGetValue(ReadOnlySpan segment, bool isEscaped, out D
return false;
}
+ [SkipLocalsInit]
public static unsafe bool TryGetEscapedDateTimeOffset(ReadOnlySpan source, out DateTimeOffset value)
{
Debug.Assert(source.Length <= JsonConstants.MaximumEscapedDateTimeOffsetParseLength);
@@ -273,6 +275,7 @@ public static bool TryGetValue(ReadOnlySpan segment, bool isEscaped, out G
return false;
}
+ [SkipLocalsInit]
public static unsafe bool TryGetEscapedGuid(ReadOnlySpan source, out Guid value)
{
Debug.Assert(source.Length <= JsonConstants.MaximumEscapedGuidLength);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs
index 578b7d5d8e3b0b..a7c0d871f28c98 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs
@@ -535,6 +535,7 @@ private bool ConsumeLiteralMultiSegment(ReadOnlySpan literal, JsonTokenTyp
return true;
}
+ [SkipLocalsInit]
private unsafe bool CheckLiteralMultiSegment(ReadOnlySpan span, ReadOnlySpan literal, out int consumed)
{
Debug.Assert(span.Length > 0 && span[0] == literal[0] && literal.Length <= JsonConstants.MaximumLiteralLength);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.TryGet.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.TryGet.cs
index 6abc48478771d6..9e7ba26edf0a43 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.TryGet.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.TryGet.cs
@@ -140,6 +140,7 @@ public readonly int CopyString(Span destination)
return CopyValue(destination);
}
+ [SkipLocalsInit]
internal readonly unsafe int CopyValue(Span destination)
{
Debug.Assert(_tokenType is JsonTokenType.String or JsonTokenType.PropertyName or JsonTokenType.Number);
@@ -192,6 +193,7 @@ internal readonly unsafe int CopyValue(Span destination)
return charsWritten;
}
+ [SkipLocalsInit]
private readonly unsafe bool TryCopyEscapedString(Span destination, out int bytesWritten)
{
Debug.Assert(_tokenType is JsonTokenType.String or JsonTokenType.PropertyName);
@@ -1241,6 +1243,7 @@ public bool TryGetDateTime(out DateTime value)
return TryGetDateTimeCore(out value);
}
+ [SkipLocalsInit]
internal unsafe bool TryGetDateTimeCore(out DateTime value)
{
scoped ReadOnlySpan span;
@@ -1286,6 +1289,7 @@ public bool TryGetDateTimeOffset(out DateTimeOffset value)
return TryGetDateTimeOffsetCore(out value);
}
+ [SkipLocalsInit]
internal unsafe bool TryGetDateTimeOffsetCore(out DateTimeOffset value)
{
scoped ReadOnlySpan span;
@@ -1332,6 +1336,7 @@ public bool TryGetGuid(out Guid value)
return TryGetGuidCore(out value);
}
+ [SkipLocalsInit]
internal unsafe bool TryGetGuidCore(out Guid value)
{
scoped ReadOnlySpan span;
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs
index dd1cb741873c09..354c1cd0db6c51 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs
@@ -521,6 +521,7 @@ private readonly bool TextEqualsHelper(ReadOnlySpan otherUtf8Text)
/// if required. The look up text is matched as is, without any modifications to it.
///
///
+ [SkipLocalsInit]
public readonly unsafe bool ValueTextEquals(ReadOnlySpan text)
{
if (!IsTokenTypeString(TokenType))
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/CharConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/CharConverter.cs
index 897f4912419024..d0b573f210dbab 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/CharConverter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/CharConverter.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
+using System.Runtime.CompilerServices;
using System.Text.Json.Schema;
namespace System.Text.Json.Serialization.Converters
@@ -10,6 +11,7 @@ internal sealed class CharConverter : JsonPrimitiveConverter
{
private const int MaxEscapedCharacterLength = JsonConstants.MaxExpansionFactorWhileEscaping;
+ [SkipLocalsInit]
public override unsafe char Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType is not (JsonTokenType.String or JsonTokenType.PropertyName))
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/DateOnlyConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/DateOnlyConverter.cs
index f9a76a7c944ab5..175c21a5e16ce1 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/DateOnlyConverter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/DateOnlyConverter.cs
@@ -1,8 +1,9 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.CompilerServices;
using System.Text.Json.Schema;
namespace System.Text.Json.Serialization.Converters
@@ -28,6 +29,7 @@ internal override DateOnly ReadAsPropertyNameCore(ref Utf8JsonReader reader, Typ
return ReadCore(ref reader);
}
+ [SkipLocalsInit]
private static unsafe DateOnly ReadCore(ref Utf8JsonReader reader)
{
if (!JsonHelpers.IsInRangeInclusive(reader.ValueLength, FormatLength, MaxEscapedFormatLength))
@@ -62,6 +64,7 @@ private static unsafe DateOnly ReadCore(ref Utf8JsonReader reader)
return value;
}
+ [SkipLocalsInit]
public override unsafe void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
{
Span buffer = stackalloc byte[FormatLength];
@@ -70,6 +73,7 @@ public override unsafe void Write(Utf8JsonWriter writer, DateOnly value, JsonSer
writer.WriteStringValue(buffer);
}
+ [SkipLocalsInit]
internal override unsafe void WriteAsPropertyNameCore(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options, bool isWritingExtensionDataProperty)
{
Span buffer = stackalloc byte[FormatLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs
index ebc89780decd41..1776d62b5846ef 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs
@@ -233,6 +233,7 @@ internal override void WriteAsPropertyNameCore(Utf8JsonWriter writer, T value, J
}
}
+ [SkipLocalsInit]
private unsafe bool TryParseEnumFromString(ref Utf8JsonReader reader, out T result)
{
Debug.Assert(reader.TokenType is JsonTokenType.String or JsonTokenType.PropertyName);
@@ -393,6 +394,7 @@ private static T ConvertFromUInt64(ulong value)
///
/// Attempt to format the enum value as a comma-separated string of flag values, or returns false if not a valid flag combination.
///
+ [SkipLocalsInit]
private unsafe string FormatEnumAsString(ulong key, T value, JsonNamingPolicy? dictionaryKeyPolicy)
{
Debug.Assert(IsDefinedValueOrCombinationOfValues(key), "must only be invoked against valid enum values.");
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/HalfConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/HalfConverter.cs
index dba31e9259fa58..ec3b01cd81adec 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/HalfConverter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/HalfConverter.cs
@@ -1,9 +1,10 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Buffers;
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.CompilerServices;
using System.Text.Json.Nodes;
using System.Text.Json.Schema;
@@ -45,6 +46,7 @@ public override void Write(Utf8JsonWriter writer, Half value, JsonSerializerOpti
WriteCore(writer, value);
}
+ [SkipLocalsInit]
private static unsafe Half ReadCore(ref Utf8JsonReader reader)
{
Half result;
@@ -74,6 +76,7 @@ private static unsafe Half ReadCore(ref Utf8JsonReader reader)
return result;
}
+ [SkipLocalsInit]
private static unsafe void WriteCore(Utf8JsonWriter writer, Half value)
{
Span buffer = stackalloc byte[MaxFormatLength];
@@ -87,6 +90,7 @@ internal override Half ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type ty
return ReadCore(ref reader);
}
+ [SkipLocalsInit]
internal override unsafe void WriteAsPropertyNameCore(Utf8JsonWriter writer, Half value, JsonSerializerOptions options, bool isWritingExtensionDataProperty)
{
Span buffer = stackalloc byte[MaxFormatLength];
@@ -126,6 +130,7 @@ internal override Half ReadNumberWithCustomHandling(ref Utf8JsonReader reader, J
return ReadCore(ref reader);
}
+ [SkipLocalsInit]
internal override unsafe void WriteNumberWithCustomHandling(Utf8JsonWriter writer, Half value, JsonNumberHandling handling)
{
if ((JsonNumberHandling.WriteAsString & handling) != 0)
@@ -152,6 +157,7 @@ internal override unsafe void WriteNumberWithCustomHandling(Utf8JsonWriter write
internal override JsonSchema? GetSchema(JsonNumberHandling numberHandling) =>
GetSchemaForNumericType(JsonSchemaType.Number, numberHandling, isIeeeFloatingPoint: true);
+ [SkipLocalsInit]
private static unsafe bool TryGetFloatingPointConstant(ref Utf8JsonReader reader, out Half value)
{
scoped Span buffer;
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/Int128Converter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/Int128Converter.cs
index 9b9460cdc7fe3b..326eb5dbab9f06 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/Int128Converter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/Int128Converter.cs
@@ -1,9 +1,10 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Buffers;
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.CompilerServices;
using System.Text.Json.Nodes;
using System.Text.Json.Schema;
@@ -44,6 +45,7 @@ public override void Write(Utf8JsonWriter writer, Int128 value, JsonSerializerOp
WriteCore(writer, value);
}
+ [SkipLocalsInit]
private static unsafe Int128 ReadCore(ref Utf8JsonReader reader)
{
int bufferLength = reader.ValueLength;
@@ -67,6 +69,7 @@ private static unsafe Int128 ReadCore(ref Utf8JsonReader reader)
return result;
}
+ [SkipLocalsInit]
private static unsafe void WriteCore(Utf8JsonWriter writer, Int128 value)
{
Span buffer = stackalloc byte[MaxFormatLength];
@@ -80,6 +83,7 @@ internal override Int128 ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type
return ReadCore(ref reader);
}
+ [SkipLocalsInit]
internal override unsafe void WriteAsPropertyNameCore(Utf8JsonWriter writer, Int128 value, JsonSerializerOptions options, bool isWritingExtensionDataProperty)
{
Span buffer = stackalloc byte[MaxFormatLength];
@@ -103,6 +107,7 @@ internal override Int128 ReadNumberWithCustomHandling(ref Utf8JsonReader reader,
return ReadCore(ref reader);
}
+ [SkipLocalsInit]
internal override unsafe void WriteNumberWithCustomHandling(Utf8JsonWriter writer, Int128 value, JsonNumberHandling handling)
{
if ((JsonNumberHandling.WriteAsString & handling) != 0)
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeOnlyConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeOnlyConverter.cs
index 8333532b2e7f2a..2707a59983328f 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeOnlyConverter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeOnlyConverter.cs
@@ -1,8 +1,9 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
using System.Text.Json.Nodes;
using System.Text.Json.Schema;
@@ -30,6 +31,7 @@ internal override TimeOnly ReadAsPropertyNameCore(ref Utf8JsonReader reader, Typ
return ReadCore(ref reader);
}
+ [SkipLocalsInit]
private static unsafe TimeOnly ReadCore(ref Utf8JsonReader reader)
{
Debug.Assert(reader.TokenType is JsonTokenType.String or JsonTokenType.PropertyName);
@@ -76,6 +78,7 @@ private static unsafe TimeOnly ReadCore(ref Utf8JsonReader reader)
return TimeOnly.FromTimeSpan(timespan);
}
+ [SkipLocalsInit]
public override unsafe void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options)
{
Span output = stackalloc byte[MaximumTimeOnlyFormatLength];
@@ -86,6 +89,7 @@ public override unsafe void Write(Utf8JsonWriter writer, TimeOnly value, JsonSer
writer.WriteStringValue(output.Slice(0, bytesWritten));
}
+ [SkipLocalsInit]
internal override unsafe void WriteAsPropertyNameCore(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options, bool isWritingExtensionDataProperty)
{
Span output = stackalloc byte[MaximumTimeOnlyFormatLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeSpanConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeSpanConverter.cs
index 46b3e6f90d9ffe..a2d6ca7815efe7 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeSpanConverter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeSpanConverter.cs
@@ -3,6 +3,7 @@
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
using System.Text.Json.Nodes;
using System.Text.Json.Schema;
@@ -30,6 +31,7 @@ internal override TimeSpan ReadAsPropertyNameCore(ref Utf8JsonReader reader, Typ
return ReadCore(ref reader);
}
+ [SkipLocalsInit]
private static unsafe TimeSpan ReadCore(ref Utf8JsonReader reader)
{
Debug.Assert(reader.TokenType is JsonTokenType.String or JsonTokenType.PropertyName);
@@ -74,6 +76,7 @@ private static unsafe TimeSpan ReadCore(ref Utf8JsonReader reader)
return tmpValue;
}
+ [SkipLocalsInit]
public override unsafe void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
{
Span output = stackalloc byte[MaximumTimeSpanFormatLength];
@@ -84,6 +87,7 @@ public override unsafe void Write(Utf8JsonWriter writer, TimeSpan value, JsonSer
writer.WriteStringValue(output.Slice(0, bytesWritten));
}
+ [SkipLocalsInit]
internal override unsafe void WriteAsPropertyNameCore(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options, bool isWritingExtensionDataProperty)
{
Span output = stackalloc byte[MaximumTimeSpanFormatLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UInt128Converter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UInt128Converter.cs
index 901ee3ea98bc5b..c56ba172489e5c 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UInt128Converter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/UInt128Converter.cs
@@ -1,9 +1,10 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Buffers;
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.CompilerServices;
using System.Text.Json.Nodes;
using System.Text.Json.Schema;
@@ -44,6 +45,7 @@ public override void Write(Utf8JsonWriter writer, UInt128 value, JsonSerializerO
WriteCore(writer, value);
}
+ [SkipLocalsInit]
private static unsafe UInt128 ReadCore(ref Utf8JsonReader reader)
{
int bufferLength = reader.ValueLength;
@@ -67,6 +69,7 @@ private static unsafe UInt128 ReadCore(ref Utf8JsonReader reader)
return result;
}
+ [SkipLocalsInit]
private static unsafe void WriteCore(Utf8JsonWriter writer, UInt128 value)
{
Span buffer = stackalloc byte[MaxFormatLength];
@@ -80,6 +83,7 @@ internal override UInt128 ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type
return ReadCore(ref reader);
}
+ [SkipLocalsInit]
internal override unsafe void WriteAsPropertyNameCore(Utf8JsonWriter writer, UInt128 value, JsonSerializerOptions options, bool isWritingExtensionDataProperty)
{
Span buffer = stackalloc byte[MaxFormatLength];
@@ -103,6 +107,7 @@ internal override UInt128 ReadNumberWithCustomHandling(ref Utf8JsonReader reader
return ReadCore(ref reader);
}
+ [SkipLocalsInit]
internal override unsafe void WriteNumberWithCustomHandling(Utf8JsonWriter writer, UInt128 value, JsonNumberHandling handling)
{
if ((JsonNumberHandling.WriteAsString & handling) != 0)
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/VersionConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/VersionConverter.cs
index e195f95669875e..e795f9292b1ca3 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/VersionConverter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/VersionConverter.cs
@@ -1,8 +1,9 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Buffers;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
using System.Text.Json.Nodes;
using System.Text.Json.Schema;
@@ -29,6 +30,7 @@ internal sealed class VersionConverter : JsonPrimitiveConverter
return ReadCore(ref reader);
}
+ [SkipLocalsInit]
private static unsafe Version ReadCore(ref Utf8JsonReader reader)
{
Debug.Assert(reader.TokenType is JsonTokenType.PropertyName or JsonTokenType.String);
@@ -96,6 +98,7 @@ private static bool IsWhiteSpaceByte(byte b)
}
#endif
+ [SkipLocalsInit]
public override unsafe void Write(Utf8JsonWriter writer, Version? value, JsonSerializerOptions options)
{
if (value is null)
@@ -119,6 +122,7 @@ internal override Version ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type
return ReadCore(ref reader);
}
+ [SkipLocalsInit]
internal override unsafe void WriteAsPropertyNameCore(Utf8JsonWriter writer, Version value, JsonSerializerOptions options, bool isWritingExtensionDataProperty)
{
ArgumentNullException.ThrowIfNull(value);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs
index 99811bcfdab7e5..ebd765ccc70c99 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
@@ -378,6 +379,7 @@ public static partial class JsonSerializer
return ReadFromSpanAsObject(json, jsonTypeInfo);
}
+ [SkipLocalsInit]
private static unsafe TValue? ReadFromSpan(ReadOnlySpan json, JsonTypeInfo jsonTypeInfo)
{
Debug.Assert(jsonTypeInfo.IsConfigured);
@@ -409,6 +411,7 @@ public static partial class JsonSerializer
}
}
+ [SkipLocalsInit]
private static unsafe object? ReadFromSpanAsObject(ReadOnlySpan json, JsonTypeInfo jsonTypeInfo)
{
Debug.Assert(jsonTypeInfo.IsConfigured);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs b/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs
index 2f889809d98dcc..540ea18a011747 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs
@@ -9,6 +9,7 @@
using System.Globalization;
using System.IO.Pipelines;
using System.Reflection;
+using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
@@ -370,6 +371,7 @@ public static void ThrowJsonException_DuplicatePropertyNotAllowed(ReadOnlySpan str)
{
const int MaxLength = 15;
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.Date.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.Date.cs
index 105ecc8e82f7c8..013f3ced8853e9 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.Date.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.Date.cs
@@ -12,6 +12,7 @@ internal static partial class JsonWriterHelper
{
private static readonly StandardFormat s_dateTimeStandardFormat = new StandardFormat('O');
+ [SkipLocalsInit]
public static unsafe void WriteDateTimeTrimmed(Span buffer, DateTime value, out int bytesWritten)
{
Span tempSpan = stackalloc byte[JsonConstants.MaximumFormatDateTimeOffsetLength];
@@ -21,6 +22,7 @@ public static unsafe void WriteDateTimeTrimmed(Span buffer, DateTime value
tempSpan.Slice(0, bytesWritten).CopyTo(buffer);
}
+ [SkipLocalsInit]
public static unsafe void WriteDateTimeOffsetTrimmed(Span buffer, DateTimeOffset value, out int bytesWritten)
{
Span tempSpan = stackalloc byte[JsonConstants.MaximumFormatDateTimeOffsetLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.cs
index ba070e24f4fbc8..f9575044ac011a 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.cs
@@ -302,6 +302,7 @@ internal static OperationStatus ToUtf8(ReadOnlySpan source, Span des
internal delegate T WriteCallback(ReadOnlySpan serializedValue);
+ [SkipLocalsInit]
internal static unsafe T WriteString(ReadOnlySpan utf8Value, WriteCallback writeCallback)
{
int firstByteToEscape = JsonWriterHelper.NeedsEscaping(utf8Value, JavaScriptEncoder.Default);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Bytes.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Bytes.cs
index 6634d5fef9f7cf..df29a3bee121ad 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Bytes.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Bytes.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -131,6 +132,7 @@ private void WriteBase64Escape(ReadOnlySpan utf8PropertyName, ReadOnlySpan
}
}
+ [SkipLocalsInit]
private unsafe void WriteBase64EscapeProperty(ReadOnlySpan propertyName, ReadOnlySpan bytes, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -154,6 +156,7 @@ private unsafe void WriteBase64EscapeProperty(ReadOnlySpan propertyName, R
}
}
+ [SkipLocalsInit]
private unsafe void WriteBase64EscapeProperty(ReadOnlySpan utf8PropertyName, ReadOnlySpan bytes, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTime.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTime.cs
index 0e61386aec9315..77549c46c545a4 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTime.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTime.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -138,6 +139,7 @@ private void WriteStringEscape(ReadOnlySpan utf8PropertyName, DateTime val
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeProperty(ReadOnlySpan propertyName, DateTime value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -161,6 +163,7 @@ private unsafe void WriteStringEscapeProperty(ReadOnlySpan propertyName, D
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeProperty(ReadOnlySpan utf8PropertyName, DateTime value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -376,6 +379,7 @@ private void WriteStringIndented(ReadOnlySpan escapedPropertyName, DateTim
output[BytesPending++] = JsonConstants.Quote;
}
+ [SkipLocalsInit]
internal unsafe void WritePropertyName(DateTime value)
{
Span buffer = stackalloc byte[JsonConstants.MaximumFormatDateTimeOffsetLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTimeOffset.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTimeOffset.cs
index 0866fca73a569d..11a6f573f7b1af 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTimeOffset.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTimeOffset.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -137,6 +138,7 @@ private void WriteStringEscape(ReadOnlySpan utf8PropertyName, DateTimeOffs
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeProperty(ReadOnlySpan propertyName, DateTimeOffset value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -160,6 +162,7 @@ private unsafe void WriteStringEscapeProperty(ReadOnlySpan propertyName, D
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeProperty(ReadOnlySpan utf8PropertyName, DateTimeOffset value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -375,6 +378,7 @@ private void WriteStringIndented(ReadOnlySpan escapedPropertyName, DateTim
output[BytesPending++] = JsonConstants.Quote;
}
+ [SkipLocalsInit]
internal unsafe void WritePropertyName(DateTimeOffset value)
{
Span buffer = stackalloc byte[JsonConstants.MaximumFormatDateTimeOffsetLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Decimal.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Decimal.cs
index 78899594230658..494e4aa31052d2 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Decimal.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Decimal.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -137,6 +138,7 @@ private void WriteNumberEscape(ReadOnlySpan utf8PropertyName, decimal valu
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, decimal value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -160,6 +162,7 @@ private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, d
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, decimal value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -363,6 +366,7 @@ private void WriteNumberIndented(ReadOnlySpan escapedPropertyName, decimal
BytesPending += bytesWritten;
}
+ [SkipLocalsInit]
internal unsafe void WritePropertyName(decimal value)
{
Span utf8PropertyName = stackalloc byte[JsonConstants.MaximumFormatDecimalLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Double.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Double.cs
index b1de9a53a86713..42aaa2c22c5754 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Double.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Double.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -141,6 +142,7 @@ private void WriteNumberEscape(ReadOnlySpan utf8PropertyName, double value
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, double value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -164,6 +166,7 @@ private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, d
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, double value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -367,6 +370,7 @@ private void WriteNumberIndented(ReadOnlySpan escapedPropertyName, double
BytesPending += bytesWritten;
}
+ [SkipLocalsInit]
internal unsafe void WritePropertyName(double value)
{
JsonWriterHelper.ValidateDouble(value);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Float.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Float.cs
index 3b118ff46ccc5a..059bebd193cb59 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Float.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Float.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -141,6 +142,7 @@ private void WriteNumberEscape(ReadOnlySpan utf8PropertyName, float value)
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, float value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -164,6 +166,7 @@ private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, f
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, float value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -367,6 +370,7 @@ private void WriteNumberIndented(ReadOnlySpan escapedPropertyName, float v
BytesPending += bytesWritten;
}
+ [SkipLocalsInit]
internal unsafe void WritePropertyName(float value)
{
Span utf8PropertyName = stackalloc byte[JsonConstants.MaximumFormatSingleLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.FormattedNumber.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.FormattedNumber.cs
index 596693ca089f8c..9cf219c86a9933 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.FormattedNumber.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.FormattedNumber.cs
@@ -3,6 +3,7 @@
using System.Buffers;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -111,6 +112,7 @@ private void WriteNumberEscape(ReadOnlySpan utf8PropertyName, ReadOnlySpan
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, ReadOnlySpan value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -134,6 +136,7 @@ private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, R
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, ReadOnlySpan value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Guid.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Guid.cs
index db28f991fcb69d..4aa83b34230d07 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Guid.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Guid.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -137,6 +138,7 @@ private void WriteStringEscape(ReadOnlySpan utf8PropertyName, Guid value)
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeProperty(ReadOnlySpan propertyName, Guid value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -160,6 +162,7 @@ private unsafe void WriteStringEscapeProperty(ReadOnlySpan propertyName, G
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeProperty(ReadOnlySpan utf8PropertyName, Guid value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -379,6 +382,7 @@ private void WriteStringIndented(ReadOnlySpan escapedPropertyName, Guid va
output[BytesPending++] = JsonConstants.Quote;
}
+ [SkipLocalsInit]
internal unsafe void WritePropertyName(Guid value)
{
Span utf8PropertyName = stackalloc byte[JsonConstants.MaximumFormatGuidLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Literal.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Literal.cs
index 114496443b3daf..8f429c0208b241 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Literal.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Literal.cs
@@ -256,6 +256,7 @@ private void WriteLiteralEscape(ReadOnlySpan utf8PropertyName, ReadOnlySpa
}
}
+ [SkipLocalsInit]
private unsafe void WriteLiteralEscapeProperty(ReadOnlySpan propertyName, ReadOnlySpan value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -279,6 +280,7 @@ private unsafe void WriteLiteralEscapeProperty(ReadOnlySpan propertyName,
}
}
+ [SkipLocalsInit]
private unsafe void WriteLiteralEscapeProperty(ReadOnlySpan utf8PropertyName, ReadOnlySpan value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -510,6 +512,7 @@ private void WriteLiteralIndented(ReadOnlySpan escapedPropertyName, ReadOn
BytesPending += value.Length;
}
+ [SkipLocalsInit]
internal unsafe void WritePropertyName(bool value)
{
Span utf8PropertyName = stackalloc byte[JsonConstants.MaximumFormatBooleanLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.SignedNumber.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.SignedNumber.cs
index c8193930b416d8..960c85a93295f0 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.SignedNumber.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.SignedNumber.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -210,6 +211,7 @@ private void WriteNumberEscape(ReadOnlySpan utf8PropertyName, long value)
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, long value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -233,6 +235,7 @@ private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, l
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, long value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -439,6 +442,7 @@ private void WriteNumberIndented(ReadOnlySpan escapedPropertyName, long va
internal void WritePropertyName(int value)
=> WritePropertyName((long)value);
+ [SkipLocalsInit]
internal unsafe void WritePropertyName(long value)
{
Span utf8PropertyName = stackalloc byte[JsonConstants.MaximumFormatInt64Length];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.String.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.String.cs
index ce9ceab57e9d1e..0dda59c5db0969 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.String.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.String.cs
@@ -107,6 +107,7 @@ public void WritePropertyName(ReadOnlySpan propertyName)
_commentAfterNoneOrPropertyName = false;
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeProperty(scoped ReadOnlySpan propertyName, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -266,6 +267,7 @@ private void WritePropertyNameUnescaped(ReadOnlySpan utf8PropertyName)
_commentAfterNoneOrPropertyName = false;
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeProperty(scoped ReadOnlySpan utf8PropertyName, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -891,6 +893,7 @@ public void WriteString(ReadOnlySpan utf8PropertyName, string? value)
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeValueOnly(ReadOnlySpan escapedPropertyName, ReadOnlySpan utf8Value, int firstEscapeIndex)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8Value.Length);
@@ -914,6 +917,7 @@ private unsafe void WriteStringEscapeValueOnly(ReadOnlySpan escapedPropert
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeValueOnly(ReadOnlySpan escapedPropertyName, ReadOnlySpan value, int firstEscapeIndex)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= value.Length);
@@ -937,6 +941,7 @@ private unsafe void WriteStringEscapeValueOnly(ReadOnlySpan escapedPropert
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapePropertyOnly(ReadOnlySpan propertyName, ReadOnlySpan escapedValue, int firstEscapeIndex)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -960,6 +965,7 @@ private unsafe void WriteStringEscapePropertyOnly(ReadOnlySpan propertyNam
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapePropertyOnly(ReadOnlySpan utf8PropertyName, ReadOnlySpan escapedValue, int firstEscapeIndex)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -1059,6 +1065,7 @@ private void WriteStringEscape(ReadOnlySpan utf8PropertyName, ReadOnlySpan
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapePropertyOrValue(scoped ReadOnlySpan propertyName, scoped ReadOnlySpan value, int firstEscapeIndexProp, int firstEscapeIndexVal)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= value.Length);
@@ -1119,6 +1126,7 @@ private unsafe void WriteStringEscapePropertyOrValue(scoped ReadOnlySpan p
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapePropertyOrValue(scoped ReadOnlySpan utf8PropertyName, scoped ReadOnlySpan utf8Value, int firstEscapeIndexProp, int firstEscapeIndexVal)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8Value.Length);
@@ -1179,6 +1187,7 @@ private unsafe void WriteStringEscapePropertyOrValue(scoped ReadOnlySpan u
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapePropertyOrValue(scoped ReadOnlySpan propertyName, scoped ReadOnlySpan utf8Value, int firstEscapeIndexProp, int firstEscapeIndexVal)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8Value.Length);
@@ -1239,6 +1248,7 @@ private unsafe void WriteStringEscapePropertyOrValue(scoped ReadOnlySpan p
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapePropertyOrValue(scoped ReadOnlySpan utf8PropertyName, scoped ReadOnlySpan value, int firstEscapeIndexProp, int firstEscapeIndexVal)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= value.Length);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.UnsignedNumber.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.UnsignedNumber.cs
index a6f60827847f05..55a422340bb9ea 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.UnsignedNumber.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.UnsignedNumber.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -219,6 +220,7 @@ private void WriteNumberEscape(ReadOnlySpan utf8PropertyName, ulong value)
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, ulong value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);
@@ -242,6 +244,7 @@ private unsafe void WriteNumberEscapeProperty(ReadOnlySpan propertyName, u
}
}
+ [SkipLocalsInit]
private unsafe void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, ulong value, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -448,6 +451,7 @@ private void WriteNumberIndented(ReadOnlySpan escapedPropertyName, ulong v
internal void WritePropertyName(uint value)
=> WritePropertyName((ulong)value);
+ [SkipLocalsInit]
internal unsafe void WritePropertyName(ulong value)
{
Span utf8PropertyName = stackalloc byte[JsonConstants.MaximumFormatUInt64Length];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Decimal.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Decimal.cs
index 377f6ce347dc63..3d0dacbcd9a0a9 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Decimal.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Decimal.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -94,6 +95,7 @@ private void WriteNumberValueIndented(decimal value)
BytesPending += bytesWritten;
}
+ [SkipLocalsInit]
internal unsafe void WriteNumberValueAsString(decimal value)
{
Span utf8Number = stackalloc byte[JsonConstants.MaximumFormatDecimalLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Double.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Double.cs
index 180bf02f825c65..84df9081015d9f 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Double.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Double.cs
@@ -5,6 +5,7 @@
using System.Buffers.Text;
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -142,6 +143,7 @@ private static bool TryFormatDouble(double value, Span destination, out in
#endif
}
+ [SkipLocalsInit]
internal unsafe void WriteNumberValueAsString(double value)
{
Span utf8Number = stackalloc byte[JsonConstants.MaximumFormatDoubleLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Float.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Float.cs
index a147969be57089..efeb191bed0d51 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Float.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Float.cs
@@ -5,6 +5,7 @@
using System.Buffers.Text;
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -142,6 +143,7 @@ private static bool TryFormatSingle(float value, Span destination, out int
#endif
}
+ [SkipLocalsInit]
internal unsafe void WriteNumberValueAsString(float value)
{
Span utf8Number = stackalloc byte[JsonConstants.MaximumFormatSingleLength];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Raw.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Raw.cs
index 965141d3d628fc..683ce2f254c1da 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Raw.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Raw.cs
@@ -1,9 +1,10 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Buffers;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -190,6 +191,7 @@ public void WriteRawValue(ReadOnlySequence utf8Json, bool skipInputValidat
SetFlagToAddListSeparatorBeforeNextItem();
}
+ [SkipLocalsInit]
private unsafe void TranscodeAndWriteRawValue(ReadOnlySpan json, bool skipInputValidation)
{
if (json.Length > JsonConstants.MaxUtf16RawValueLength)
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.SignedNumber.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.SignedNumber.cs
index 9f3075c430077a..667a51d8481d10 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.SignedNumber.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.SignedNumber.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -107,6 +108,7 @@ private void WriteNumberValueIndented(long value)
BytesPending += bytesWritten;
}
+ [SkipLocalsInit]
internal unsafe void WriteNumberValueAsString(long value)
{
Span utf8Number = stackalloc byte[JsonConstants.MaximumFormatInt64Length];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.String.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.String.cs
index d629f98ebc4e76..adf28e4a589bf4 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.String.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.String.cs
@@ -3,6 +3,7 @@
using System.Buffers;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -178,6 +179,7 @@ private void WriteStringIndented(ReadOnlySpan escapedValue, int maxRequire
output[BytesPending++] = JsonConstants.Quote;
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeValue(ReadOnlySpan value, int firstEscapeIndexVal)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= value.Length);
@@ -329,6 +331,7 @@ private void WriteStringIndented(ReadOnlySpan escapedValue)
output[BytesPending++] = JsonConstants.Quote;
}
+ [SkipLocalsInit]
private unsafe void WriteStringEscapeValue(ReadOnlySpan utf8Value, int firstEscapeIndexVal)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8Value.Length);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.StringSegment.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.StringSegment.cs
index 54cd5e14621abe..7c1540a87f17f4 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.StringSegment.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.StringSegment.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -61,6 +62,7 @@ public void WriteStringValueSegment(ReadOnlySpan value, bool isFinalSegmen
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringSegmentWithLeftover(scoped ReadOnlySpan value, bool isFinalSegment)
{
Debug.Assert(HasPartialStringData);
@@ -130,6 +132,7 @@ private void WriteStringSegmentEscape(ReadOnlySpan value, bool isFinalSegm
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringSegmentEscapeValue(ReadOnlySpan value, int firstEscapeIndexVal, bool isFinalSegment)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= value.Length);
@@ -229,6 +232,7 @@ public void WriteStringValueSegment(ReadOnlySpan value, bool isFinalSegmen
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringSegmentWithLeftover(scoped ReadOnlySpan utf8Value, bool isFinalSegment)
{
Debug.Assert(HasPartialStringData);
@@ -299,6 +303,7 @@ private void WriteStringSegmentEscape(ReadOnlySpan utf8Value, bool isFinal
}
}
+ [SkipLocalsInit]
private unsafe void WriteStringSegmentEscapeValue(ReadOnlySpan utf8Value, int firstEscapeIndexVal, bool isFinalSegment)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8Value.Length);
@@ -396,6 +401,7 @@ public void WriteBase64StringSegment(ReadOnlySpan value, bool isFinalSegme
}
}
+ [SkipLocalsInit]
private unsafe void WriteBase64StringSegmentWithLeftover(scoped ReadOnlySpan bytes, bool isFinalSegment)
{
Debug.Assert(HasPartialStringData);
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.UnsignedNumber.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.UnsignedNumber.cs
index 170d0664ef7bba..5fb33652179a2e 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.UnsignedNumber.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.UnsignedNumber.cs
@@ -4,6 +4,7 @@
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Text.Json
{
@@ -109,6 +110,7 @@ private void WriteNumberValueIndented(ulong value)
BytesPending += bytesWritten;
}
+ [SkipLocalsInit]
internal unsafe void WriteNumberValueAsString(ulong value)
{
Span utf8Number = stackalloc byte[JsonConstants.MaximumFormatUInt64Length];
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs
index 1f8ce040a5c223..e709c6753c72eb 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs
@@ -856,6 +856,7 @@ private void WriteStartByOptions(ReadOnlySpan utf8PropertyName, byte token
}
}
+ [SkipLocalsInit]
private unsafe void WriteStartEscapeProperty(ReadOnlySpan utf8PropertyName, byte token, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= utf8PropertyName.Length);
@@ -1005,6 +1006,7 @@ private void WriteStartByOptions(ReadOnlySpan propertyName, byte token)
}
}
+ [SkipLocalsInit]
private unsafe void WriteStartEscapeProperty(ReadOnlySpan propertyName, byte token, int firstEscapeIndexProp)
{
Debug.Assert(int.MaxValue / JsonConstants.MaxExpansionFactorWhileEscaping >= propertyName.Length);