#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(); 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);
} }
} }