Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Minimize overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
gfoidl committed Oct 21, 2019
1 parent cfacc85 commit ea2a4ba
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public static unsafe int NeedsEscaping(ReadOnlySpan<char> value, JavaScriptEncod
}

#if BUILDING_INBOX_LIBRARY
if (Sse2.IsSupported)
if (Sse2.IsSupported && value.Length >= 8)
{
short* startingAddress = (short*)ptr;
int index = 0;
Expand All @@ -263,6 +263,8 @@ public static unsafe int NeedsEscaping(ReadOnlySpan<char> value, JavaScriptEncod
startingAddress += 16;
}

// There will be maximum one "iteration", as starting with length 16 the above loop
// will be executed. But the JIT will produce better code when written as loop.
while (value.Length - 8 >= idx)
{
Debug.Assert(startingAddress >= ptr && startingAddress <= (ptr + value.Length - 8));
Expand Down

0 comments on commit ea2a4ba

Please sign in to comment.