Skip to content

Commit c3d02b0

Browse files
committed
Refactor the logic to evaluate every byte in the chunk if there is a byte in that chunk that needs escaping.
1 parent c9f668a commit c3d02b0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

java/src/json/ext/SWARBasicStringEncoder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ void encode(ByteList src) throws IOException {
3030
pos += 8;
3131
continue;
3232
}
33-
for (int i = 0; i < 8; i++) {
34-
int ch = Byte.toUnsignedInt(ptrBytes[ptr + pos + i]);
33+
int chunkEnd = pos + 8;
34+
while (pos < chunkEnd) {
35+
int ch = Byte.toUnsignedInt(ptrBytes[ptr + pos]);
3536
int ch_len = ESCAPE_TABLE[ch];
3637
if (ch_len > 0) {
37-
beg = pos = flushPos(pos + i, beg, ptrBytes, ptr, 1);
38+
beg = pos = flushPos(pos, beg, ptrBytes, ptr, 1);
3839
escapeAscii(ch, scratch, hexdig);
39-
break;
40+
} else {
41+
pos++;
4042
}
4143
}
4244
}

0 commit comments

Comments
 (0)