mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 11:25:30 -04:00
#863 improve performance of JSONTokener#nextString
replacing a switch-case statement with few branches by if-else cases
This commit is contained in:
parent
f38452a00c
commit
63625b3c62
@ -295,12 +295,9 @@ public class JSONTokener {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
c = this.next();
|
c = this.next();
|
||||||
switch (c) {
|
if (c == quote) {
|
||||||
case 0:
|
return sb.toString();
|
||||||
case '\n':
|
} else if (c == '\\') {
|
||||||
case '\r':
|
|
||||||
throw this.syntaxError("Unterminated string");
|
|
||||||
case '\\':
|
|
||||||
c = this.next();
|
c = this.next();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'b':
|
case 'b':
|
||||||
@ -334,11 +331,9 @@ public class JSONTokener {
|
|||||||
default:
|
default:
|
||||||
throw this.syntaxError("Illegal escape.");
|
throw this.syntaxError("Illegal escape.");
|
||||||
}
|
}
|
||||||
break;
|
} else if (c == 0 || c == '\n' || c == '\r') {
|
||||||
default:
|
throw this.syntaxError("Unterminated string");
|
||||||
if (c == quote) {
|
} else {
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user