Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jan 19, 2025
1 parent 4b9181c commit a3cbcbb
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 65 deletions.
2 changes: 0 additions & 2 deletions core/src/main/java/com/alibaba/fastjson2/JSONFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ public NameCacheEntry2(String name, long value0, long value1) {
1.0e20, 1.0e21, 1.0e22
};

static final Double DOUBLE_ZERO = (double) 0;

static {
Properties properties = Conf.DEFAULT_PROPERTIES;
{
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/java/com/alibaba/fastjson2/JSONReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,6 @@ static char char2(int c1, int c2) {
+ DIGITS2[c2]);
}

static char char4(int c1, int c2, int c3, int c4) {
return (char) (DIGITS2[c1] * 0x1000
+ DIGITS2[c2] * 0x100
+ DIGITS2[c3] * 0x10
+ DIGITS2[c4]);
}

public abstract boolean nextIfObjectStart();

public abstract boolean nextIfNullOrEmptyString();
Expand Down
32 changes: 17 additions & 15 deletions core/src/main/java/com/alibaba/fastjson2/JSONReaderASCII.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.Arrays;

import static com.alibaba.fastjson2.JSONFactory.*;
import static com.alibaba.fastjson2.JSONReaderJSONB.check3;
import static com.alibaba.fastjson2.util.IOUtils.hexDigit4;
import static com.alibaba.fastjson2.util.JDKUtils.*;

class JSONReaderASCII
Expand Down Expand Up @@ -141,7 +143,7 @@ public final long readFieldNameHashCode() {
}

final int quote = ch;

final int end = this.end;
this.nameAscii = true;
this.nameEscape = false;
int offset = this.nameBegin = this.offset;
Expand Down Expand Up @@ -272,7 +274,7 @@ public final long readFieldNameHashCode() {
ch = bytes[++offset];
switch (ch) {
case 'u': {
ch = char4(bytes[offset + 1], bytes[offset + 2], bytes[offset + 3], bytes[offset + 4]);
ch = hexDigit4(bytes, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -346,7 +348,7 @@ public final long readFieldNameHashCode() {
ch = bytes[++offset];
switch (ch) {
case 'u': {
ch = char4(bytes[offset + 1], bytes[offset + 2], bytes[offset + 3], bytes[offset + 4]);
ch = hexDigit4(bytes, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -453,7 +455,7 @@ public final long readFieldNameHashCodeUnquote() {
ch = (char) bytes[offset++];
switch (ch) {
case 'u': {
ch = char4(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);
ch = hexDigit4(bytes, check3(offset, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -534,7 +536,7 @@ public final long readFieldNameHashCodeUnquote() {
ch = bytes[offset++];
switch (ch) {
case 'u': {
ch = char4(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);
ch = hexDigit4(bytes, check3(offset, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -665,7 +667,7 @@ public final long readValueHashCode() {
ch = bytes[++offset];
switch (ch) {
case 'u': {
ch = char4(bytes[offset + 1], bytes[offset + 2], bytes[offset + 3], bytes[offset + 4]);
ch = hexDigit4(bytes, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -732,7 +734,7 @@ public final long readValueHashCode() {
ch = bytes[++offset];
switch (ch) {
case 'u': {
ch = char4(bytes[offset + 1], bytes[offset + 2], bytes[offset + 3], bytes[offset + 4]);
ch = hexDigit4(bytes, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -787,7 +789,7 @@ public final long readValueHashCode() {
@Override
public final long getNameHashCodeLCase() {
final byte[] bytes = this.bytes;
int offset = nameBegin;
int offset = nameBegin, end = this.end;
long nameValue = 0;
for (int i = 0; offset < end; offset++) {
int c = bytes[offset];
Expand All @@ -796,7 +798,7 @@ public final long getNameHashCodeLCase() {
c = bytes[++offset];
switch (c) {
case 'u': {
c = char4(bytes[offset + 1], bytes[offset + 2], bytes[offset + 3], bytes[offset + 4]);
c = hexDigit4(bytes, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -875,7 +877,7 @@ public final long getNameHashCodeLCase() {
c = bytes[++offset];
switch (c) {
case 'u': {
c = char4(bytes[offset + 1], bytes[offset + 2], bytes[offset + 3], bytes[offset + 4]);
c = hexDigit4(bytes, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -930,14 +932,14 @@ public final String getFieldName() {
if (JDKUtils.STRING_CREATOR_JDK11 != null) {
byte[] chars = new byte[nameLength];
forStmt:
for (int i = 0; offset < nameEnd; ++i) {
for (int i = 0, end = this.end; offset < nameEnd; ++i) {
byte b = bytes[offset];

if (b == '\\') {
b = bytes[++offset];
switch (b) {
case 'u': {
char ch = char4(bytes[offset + 1], bytes[offset + 2], bytes[offset + 3], bytes[offset + 4]);
int ch = hexDigit4(bytes, check3(offset + 1, end));
offset += 4;
if (ch > 0xFF) {
chars = null;
Expand Down Expand Up @@ -994,7 +996,7 @@ public final String getFieldName() {
ch = (char) bytes[++offset];
switch (ch) {
case 'u': {
ch = char4(bytes[offset + 1], bytes[offset + 2], bytes[offset + 3], bytes[offset + 4]);
ch = (char) hexDigit4(bytes, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -1376,7 +1378,7 @@ protected final void readString0() {
c = (char) (bytes[++offset]);
switch (c) {
case 'u': {
c = char4(bytes[offset + 1], bytes[offset + 2], bytes[offset + 3], bytes[offset + 4]);
c = (char) hexDigit4(bytes, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -1525,7 +1527,7 @@ private int readEscaped(byte[] bytes, int offset, byte quote, char[] buf) {
c = (char) bytes[++offset];
switch (c) {
case 'u': {
c = char4(bytes[offset + 1], bytes[offset + 2], bytes[offset + 3], bytes[offset + 4]);
c = (char) hexDigit4(bytes, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down
25 changes: 13 additions & 12 deletions core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.*;

import static com.alibaba.fastjson2.JSONFactory.*;
import static com.alibaba.fastjson2.JSONReaderJSONB.check3;
import static com.alibaba.fastjson2.util.IOUtils.*;
import static com.alibaba.fastjson2.util.IOUtils.INT_32_MULT_MIN_10;
import static com.alibaba.fastjson2.util.JDKUtils.*;
Expand Down Expand Up @@ -962,7 +963,7 @@ public final long readFieldNameHashCodeUnquote() {
ch = chars[offset++];
switch (ch) {
case 'u': {
ch = char4(chars[offset], chars[offset + 1], chars[offset + 2], chars[offset + 3]);
ch = (char) hexDigit4(chars, check3(offset, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -1043,7 +1044,7 @@ public final long readFieldNameHashCodeUnquote() {
ch = chars[offset++];
switch (ch) {
case 'u': {
ch = char4(chars[offset], chars[offset + 1], chars[offset + 2], chars[offset + 3]);
ch = (char) hexDigit4(chars, check3(offset, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -1293,7 +1294,7 @@ public final long readFieldNameHashCode() {
c = chars[++offset];
switch (c) {
case 'u': {
c = char4(chars[offset + 1], chars[offset + 2], chars[offset + 3], chars[offset + 4]);
c = (char) hexDigit4(chars, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -1359,7 +1360,7 @@ public final long readFieldNameHashCode() {
c = chars[++offset];
switch (c) {
case 'u': {
c = char4(chars[offset + 1], chars[offset + 2], chars[offset + 3], chars[offset + 4]);
c = (char) hexDigit4(chars, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -1446,7 +1447,7 @@ public final long readValueHashCode() {
ch = chars[++offset];
switch (ch) {
case 'u': {
ch = char4(chars[offset + 1], chars[offset + 2], chars[offset + 3], chars[offset + 4]);
ch = (char) hexDigit4(chars, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -1511,7 +1512,7 @@ public final long readValueHashCode() {
c = chars[++offset];
switch (c) {
case 'u': {
c = char4(chars[offset + 1], chars[offset + 2], chars[offset + 3], chars[offset + 4]);
c = (char) hexDigit4(chars, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -1590,7 +1591,7 @@ public final long getNameHashCodeLCase() {
c = chars[++offset];
switch (c) {
case 'u': {
c = char4(chars[offset + 1], chars[offset + 2], chars[offset + 3], chars[offset + 4]);
c = (char) hexDigit4(chars, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -1669,7 +1670,7 @@ public final long getNameHashCodeLCase() {
c = chars[++offset];
switch (c) {
case 'u': {
c = char4(chars[offset + 1], chars[offset + 2], chars[offset + 3], chars[offset + 4]);
c = (char) hexDigit4(chars, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -1726,7 +1727,7 @@ public final String getFieldName() {
c = chars[++offset];
switch (c) {
case 'u': {
c = char4(chars[offset + 1], chars[offset + 2], chars[offset + 3], chars[offset + 4]);
c = (char) hexDigit4(chars, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -2932,7 +2933,7 @@ public final String getString() {
c = chars[++offset];
switch (c) {
case 'u': {
c = char4(chars[offset + 1], chars[offset + 2], chars[offset + 3], chars[offset + 4]);
c = (char) hexDigit4(chars, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down Expand Up @@ -2991,7 +2992,7 @@ protected final void readString0() {
if (c == '\\') {
c = this.chars[++offset];
if (c == 'u') {
c = char4(chars[offset + 1], chars[offset + 2], chars[offset + 3], chars[offset + 4]);
c = (char) hexDigit4(chars, check3(offset + 1, end));
offset += 4;
} else if (c == 'x') {
c = char2(chars[offset + 1], chars[offset + 2]);
Expand Down Expand Up @@ -3101,7 +3102,7 @@ public String readString() {
c = chars[++offset];
switch (c) {
case 'u': {
c = char4(chars[offset + 1], chars[offset + 2], chars[offset + 3], chars[offset + 4]);
c = (char) hexDigit4(chars, check3(offset + 1, end));
offset += 4;
break;
}
Expand Down
Loading

0 comments on commit a3cbcbb

Please sign in to comment.