Skip to content

Commit

Permalink
Improve JSON serialization perf of longer strings on mono (dotnet#39733)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveharter authored Aug 14, 2020
1 parent a2908e3 commit ac492c9
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,19 @@ public override unsafe int FindFirstCharacterToEncode(char* text, int textLength
#endif
Debug.Assert(textLength > 0 && ptr < end);

// For performance on the Mono interpreter, avoid referencing the static table for every value.
ReadOnlySpan<byte> allowListLocal = AllowList;

do
{
Debug.Assert(text <= ptr && ptr < (text + textLength));

if (NeedsEscaping(*(char*)ptr))
char value = *(char*)ptr;

// NeedsEscaping() is lifted below for perf; verify semantics remain consistent.
Debug.Assert((value > LastAsciiCharacter || allowListLocal[value] == 0) == NeedsEscaping(value));

if (value > LastAsciiCharacter || allowListLocal[value] == 0)
{
goto Return;
}
Expand Down Expand Up @@ -276,11 +284,17 @@ public override unsafe int FindFirstCharacterToEncodeUtf8(ReadOnlySpan<byte> utf
#endif
Debug.Assert(textLength > 0 && ptr < end);

// For performance on the Mono interpreter, avoid referencing the static table for every value.
ReadOnlySpan<byte> allowListLocal = AllowList;

do
{
Debug.Assert(pValue <= ptr && ptr < (pValue + utf8Text.Length));

if (NeedsEscaping(*ptr))
// NeedsEscaping() is lifted below for perf; verify semantics remain consistent.
Debug.Assert((allowListLocal[*ptr] == 0) == NeedsEscaping(*ptr));

if (allowListLocal[*ptr] == 0)
{
goto Return;
}
Expand Down

0 comments on commit ac492c9

Please sign in to comment.