Skip to content

Commit a458201

Browse files
samyronbyroot
authored andcommitted
Use SWAR if there is still at least 4 bytes remaining.
1 parent 44b1d87 commit a458201

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

java/src/json/ext/StringEncoder.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,16 @@ void encodeBasicSWAR(ByteList src) throws IOException {
247247
pos += 8;
248248
}
249249

250-
// Handle remaining bytes one by one
251-
while (pos < len) {
252-
int ch = Byte.toUnsignedInt(ptrBytes[ptr + pos]);
253-
int ch_len = ESCAPE_TABLE[ch];
254-
if (ch_len > 0) {
255-
beg = pos = flushPos(pos, beg, ptrBytes, ptr, 1);
256-
escapeAscii(ch, scratch, hexdig);
257-
} else {
258-
pos++;
250+
if (pos + 4 <= len) {
251+
int x = bb.getInt(ptr + pos);
252+
int is_ascii = 0x808080 & ~x;
253+
int xor2 = x ^ 0x020202;
254+
int lt32_or_eq34 = xor2 - 0x212121;
255+
int sub92 = x ^ 0x5C5C5C;
256+
int eq92 = (sub92 - 0x010101);
257+
boolean skip_chunk = ((lt32_or_eq34 | eq92) & is_ascii) == 0;
258+
if (skip_chunk) {
259+
pos += 4;
259260
}
260261
}
261262

0 commit comments

Comments
 (0)