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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user