#863 improve performance of JSONTokener#nextString

replacing a switch-case statement with few branches
by if-else cases
This commit is contained in:
Simulant 2024-03-05 09:43:54 +01:00
parent f38452a00c
commit 63625b3c62

View File

@ -295,12 +295,9 @@ public class JSONTokener {
StringBuilder sb = new StringBuilder();
for (;;) {
c = this.next();
switch (c) {
case 0:
case '\n':
case '\r':
throw this.syntaxError("Unterminated string");
case '\\':
if (c == quote) {
return sb.toString();
} else if (c == '\\') {
c = this.next();
switch (c) {
case 'b':
@ -334,11 +331,9 @@ public class JSONTokener {
default:
throw this.syntaxError("Illegal escape.");
}
break;
default:
if (c == quote) {
return sb.toString();
}
} else if (c == 0 || c == '\n' || c == '\r') {
throw this.syntaxError("Unterminated string");
} else {
sb.append(c);
}
}