Skip to content

Commit fbd41e6

Browse files
Optimize union initialization by avoiding object initializer
Changed from `union = new Union { JsonRpc = string.Empty }` to `union = default; union.JsonRpc = string.Empty;` to avoid the overhead of object initializer syntax and make direct assignment to the struct field. Co-authored-by: Scooletz <scooletz@users.noreply.github.com> Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
1 parent ab670e4 commit fbd41e6

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

src/ModelContextProtocol.Core/Protocol/JsonRpcMessage.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ public override void Write(Utf8JsonWriter writer, JsonRpcMessage value, JsonSeri
156156
/// </summary>
157157
private static void ParseUnion(ref Utf8JsonReader reader, JsonSerializerOptions options, out Union union)
158158
{
159-
union = new Union
160-
{
161-
JsonRpc = string.Empty // Initialize to avoid null reference warnings
162-
};
159+
union = default;
160+
union.JsonRpc = string.Empty; // Initialize to avoid null reference warnings
163161

164162
if (reader.TokenType != JsonTokenType.StartObject)
165163
{

0 commit comments

Comments
 (0)