Skip to content

Commit

Permalink
Added small performance improvements in SystemTextJsonMessageAccessor
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Jul 16, 2024
1 parent a85bfb4 commit 02432e5
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public override void Clear()
{
_stream?.Dispose();
_stream = null;
_document?.Dispose();
_document = null;
}

Expand All @@ -261,6 +262,14 @@ public CallResult Read(ReadOnlyMemory<byte> data)

try
{
var firstByte = data.Span[0];
if (firstByte != 0x7b && firstByte != 0x5b)
{
// Value doesn't start with `{` or `[`, prevent deserialization attempt as it's slow
IsJson = false;
return new CallResult(new ServerError("Not a json value"));
}

_document = JsonDocument.Parse(data);
IsJson = true;
return new CallResult(null);
Expand Down Expand Up @@ -289,6 +298,7 @@ public override string GetOriginalString() =>
public override void Clear()
{
_bytes = null;
_document?.Dispose();
_document = null;
}
}
Expand Down

0 comments on commit 02432e5

Please sign in to comment.