Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve toString Performance: Use StringBuilderWriter for toString methods #867

Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7c7a98d
#863 use StringBuilderWriter to toString methods
Simulant87 Feb 23, 2024
0ff635c
#863 improve formatting
Simulant87 Feb 23, 2024
6660e40
#863 increase compiler stack size on build pipeline
Simulant87 Feb 23, 2024
06778bd
#863 compute initial capacity for StringBuilderWriter
Simulant87 Feb 24, 2024
d672b44
#863 add StringBuilderWriter unit test
Simulant87 Feb 24, 2024
e2194bc
#863 undo wrong optimisation, fixing failing test
Simulant87 Feb 24, 2024
d878c38
#863 reorder instanceof checks by assumed frequency
Simulant87 Feb 24, 2024
4f456d9
#863 fix changed behaviour of changing order in writeValue with JSONS…
Simulant87 Feb 25, 2024
f38452a
add a comment explaining the ordering
Simulant87 Feb 25, 2024
63625b3
#863 improve performance of JSONTokener#nextString
Simulant87 Mar 5, 2024
5407423
#863 replace usage of back() method in JSONObject parsing
Simulant87 Mar 5, 2024
c010033
#863 replace short switch statements with if-else
Simulant87 Mar 5, 2024
eda0841
Revert "#863 increase compiler stack size on build pipeline"
Simulant87 Mar 10, 2024
045324a
Revert "#863 replace short switch statements with if-else"
Simulant87 Mar 10, 2024
a3f15e5
Revert "#863 replace usage of back() method in JSONObject parsing"
Simulant87 Mar 10, 2024
5974fc1
Merge branch 'master' into 863-improve-toString-performance-StringBui…
Simulant87 Mar 10, 2024
0c5cf18
Revert "#863 improve performance of JSONTokener#nextString"
Simulant87 Mar 10, 2024
60090a7
add a test case for an enum implementing JSONString
Simulant87 Feb 25, 2024
6c35b08
#863 make StringBuilderWriter public and move test
Simulant87 Mar 10, 2024
b75da07
#863 move instanceof Enum check back to original position
Simulant87 Mar 10, 2024
6aed1cf
fix typo
Simulant87 Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#863 replace short switch statements with if-else
Simulant87 committed Mar 5, 2024
commit c010033591c192a0821bdd8fe23bc61cdc6fe738
7 changes: 3 additions & 4 deletions src/main/java/org/json/JSONObject.java
Original file line number Diff line number Diff line change
@@ -216,12 +216,11 @@ public JSONObject(JSONTokener x) throws JSONException {
}
c = x.nextClean();
for (;;) {
switch (c) {
case 0:
if (c == 0) {
throw x.syntaxError("A JSONObject text must end with '}'");
case '}':
} else if (c == '}') {
return;
default:
} else {
key = x.nextSimpleValue(c).toString();
}

9 changes: 3 additions & 6 deletions src/main/java/org/json/JSONTokener.java
Original file line number Diff line number Diff line change
@@ -397,15 +397,14 @@ public String nextTo(String delimiters) throws JSONException {
*/
public Object nextValue() throws JSONException {
char c = this.nextClean();
switch (c) {
case '{':
if (c == '{') {
this.back();
try {
return new JSONObject(this);
} catch (StackOverflowError e) {
throw new JSONException("JSON Array or Object depth too large to process.", e);
}
case '[':
} else if (c == '[') {
this.back();
try {
return new JSONArray(this);
@@ -419,9 +418,7 @@ public Object nextValue() throws JSONException {
Object nextSimpleValue(char c) {
String string;

switch (c) {
case '"':
case '\'':
if (c == '"' || c == '\'') {
return this.nextString(c);
}

Loading