Skip to content

Commit

Permalink
improved JSONValidator performance
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jul 26, 2020
1 parent f02ecfc commit e970545
Showing 1 changed file with 86 additions and 1 deletion.
87 changes: 86 additions & 1 deletion src/main/java/com/alibaba/fastjson/JSONValidator.java
Expand Up @@ -85,7 +85,11 @@ private boolean any() {
switch (ch) {
case '{':
next();
skipWhiteSpace();

while (isWhiteSpace(ch)) {
next();
}

if (ch == '}') {
next();
type = Type.Object;
Expand All @@ -106,6 +110,7 @@ private boolean any() {
return false;
}
skipWhiteSpace();

if (!any()) {
return false;
}
Expand Down Expand Up @@ -339,6 +344,36 @@ else if (ch == '"') {
}
}

protected boolean string()
{
next();
for (; !eof; ) {
if (ch == '\\') {
next();

if (ch == 'u') {
next();

next();
next();
next();
next();
} else {
next();
}
}
else if (ch == '"') {
next();
return true;
}
else {
next();
}
}

return false;
}

void skipWhiteSpace() {
while (isWhiteSpace(ch)) {
next();
Expand Down Expand Up @@ -458,6 +493,56 @@ void next() {
ch = str.charAt(pos);
}
}

protected final void fieldName()
{
for (int i = pos + 1; i < str.length(); ++i) {
char ch = str.charAt(i);
if (ch == '\\') {
break;
}
if (ch == '\"') {
this.ch = str.charAt(i + 1);
pos = i + 1;
return;
}
}

next();
for (; ; ) {
if (ch == '\\') {
next();

if (ch == 'u') {
next();

next();
next();
next();
next();
} else {
next();
}
}
else if (ch == '"') {
next();
break;
}
else {
next();
}
}
}

final void skipWhiteSpace() {
if (ch > '\r') {
return;
}

while (isWhiteSpace(ch)) {
next();
}
}
}

static class ReaderValidator extends JSONValidator {
Expand Down

0 comments on commit e970545

Please sign in to comment.