File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -130,8 +130,25 @@ public unsafe static void AdjustForSkippedBytes(byte* pInputBuffer,// int skippe
130
130
int pos = 0 ;
131
131
int nextPos ;
132
132
uint codePoint = 0 ;
133
+
133
134
while ( pos < inputLength )
134
135
{
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
+
135
152
byte firstByte = pInputBuffer [ pos ] ;
136
153
while ( firstByte < 0b10000000 )
137
154
{
@@ -631,6 +648,8 @@ public unsafe static void AdjustForSkippedBytes(byte* pInputBuffer,// int skippe
631
648
632
649
// We have processed all the blocks using SIMD, we need to process the remaining bytes.
633
650
// 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
634
653
if ( processedLength < inputLength )
635
654
{
636
655
You can’t perform that action at this time.
0 commit comments