Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jan 11, 2025
1 parent b4a816e commit fb9dc31
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions core/src/main/java/com/alibaba/fastjson2/JSONWriterUTF8.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,23 +506,24 @@ public void writeStringLatin1(byte[] value) {
}

int off = this.off;
if (!escape) {
int minCapacity = off + value.length + 2;
byte[] bytes = this.bytes;
if (minCapacity > bytes.length) {
bytes = grow(minCapacity);
}
bytes[off] = quote;
System.arraycopy(value, 0, bytes, off + 1, value.length);
off += value.length + 1;
bytes[off] = quote;
this.off = off + 1;
if (escape) {
writeStringEscaped(value);
return;
}
writeStringEscaped(value);

int minCapacity = off + value.length + 2;
byte[] bytes = this.bytes;
if (minCapacity > bytes.length) {
bytes = grow(minCapacity);
}
bytes[off] = quote;
System.arraycopy(value, 0, bytes, off + 1, value.length);
off += value.length + 1;
bytes[off] = quote;
this.off = off + 1;
}

static boolean containsEscaped(long data, long quote) {
static boolean containsEscaped(long v, long quote) {
/*
for (int i = 0; i < 8; ++i) {
byte c = (byte) data;
Expand All @@ -533,13 +534,13 @@ static boolean containsEscaped(long data, long quote) {
}
return false;
*/
long xed = data ^ quote;
long xf0 = data ^ 0x5c5c5c5c5c5c5c5cL;
long x22 = v ^ quote; // " -> 0x22, ' -> 0x27
long x5c = v ^ 0x5c5c5c5c5c5c5c5cL;

xed = (xed - 0x0101010101010101L) & ~xed;
xf0 = (xf0 - 0x0101010101010101L) & ~xf0;
x22 = (x22 - 0x0101010101010101L) & ~x22;
x5c = (x5c - 0x0101010101010101L) & ~x5c;

return ((xed | xf0 | (0x7F7F_7F7F_7F7F_7F7FL - data + 0x1010_1010_1010_1010L) | data) & 0x8080808080808080L) != 0;
return ((x22 | x5c | (0x7F7F_7F7F_7F7F_7F7FL - v + 0x1010_1010_1010_1010L) | v) & 0x8080808080808080L) != 0;
}

protected final void writeStringLatin1BrowserSecure(byte[] values) {
Expand Down

0 comments on commit fb9dc31

Please sign in to comment.