Skip to content

Commit

Permalink
Merge pull request #774 from mccartney/removing-synchronized
Browse files Browse the repository at this point in the history
Removing excessive synchronization
  • Loading branch information
stleary committed Oct 4, 2023
2 parents 1726b6c + 61bb60e commit 79af389
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/main/java/org/json/JSONArray.java
Expand Up @@ -1646,9 +1646,7 @@ public String toString() {
@SuppressWarnings("resource")
public String toString(int indentFactor) throws JSONException {
StringWriter sw = new StringWriter();
synchronized (sw.getBuffer()) {
return this.write(sw, indentFactor, 0).toString();
}
return this.write(sw, indentFactor, 0).toString();
}

/**
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/org/json/JSONObject.java
Expand Up @@ -2183,13 +2183,11 @@ public Object optQuery(JSONPointer jsonPointer) {
@SuppressWarnings("resource")
public static String quote(String string) {
StringWriter sw = new StringWriter();
synchronized (sw.getBuffer()) {
try {
return quote(string, sw).toString();
} catch (IOException ignored) {
// will never happen - we are writing to a string writer
return "";
}
try {
return quote(string, sw).toString();
} catch (IOException ignored) {
// will never happen - we are writing to a string writer
return "";
}
}

Expand Down Expand Up @@ -2576,9 +2574,7 @@ public String toString() {
@SuppressWarnings("resource")
public String toString(int indentFactor) throws JSONException {
StringWriter w = new StringWriter();
synchronized (w.getBuffer()) {
return this.write(w, indentFactor, 0).toString();
}
return this.write(w, indentFactor, 0).toString();
}

/**
Expand Down

0 comments on commit 79af389

Please sign in to comment.