Skip to content

Commit 9e31966

Browse files
committed
Save game
1 parent 7d90fde commit 9e31966

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/UTF8.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,25 @@ public unsafe static void AdjustForSkippedBytes(byte* pInputBuffer,// int skippe
130130
int pos = 0;
131131
int nextPos;
132132
uint codePoint = 0;
133+
133134
while (pos < inputLength)
134135
{
136+
// If the next 16 bytes are ascii, we can skip them.
137+
nextPos = pos + 16;
138+
if (nextPos <= inputLength)
139+
{ // if it is safe to read 16 more bytes, check that they are ascii
140+
ulong v1 = *(ulong*)pInputBuffer;
141+
ulong v2 = *(ulong*)(pInputBuffer + 8);
142+
ulong v = v1 | v2;
143+
144+
if ((v & 0x8080808080808080) == 0)
145+
{
146+
pos = nextPos;
147+
continue;
148+
}
149+
150+
}
151+
135152
byte firstByte = pInputBuffer[pos];
136153
while (firstByte < 0b10000000)
137154
{
@@ -631,6 +648,8 @@ public unsafe static void AdjustForSkippedBytes(byte* pInputBuffer,// int skippe
631648

632649
// We have processed all the blocks using SIMD, we need to process the remaining bytes.
633650
// Process the remaining bytes with the scalar function
651+
// worst possible case is 4 bytes, where we need to backtrack 3 bytes
652+
// 11110xxxx 10xxxxxx 10xxxxxx 10xxxxxx <== we might be pointing at the last byte
634653
if (processedLength < inputLength)
635654
{
636655

0 commit comments

Comments
 (0)