Skip to content

Commit 64c401a

Browse files
committed
Replace instances of StringBuffer with StringBuilder
1 parent b785e1d commit 64c401a

File tree

26 files changed

+130
-148
lines changed

26 files changed

+130
-148
lines changed

app/src/antlr/ExtendedCommonASTWithHiddenTokens.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void initialize(AST ast) {
3737
public String getHiddenAfterString() {
3838

3939
CommonHiddenStreamToken t;
40-
StringBuffer hiddenAfterString = new StringBuffer(100);
40+
StringBuilder hiddenAfterString = new StringBuilder(100);
4141

4242
for ( t = hiddenAfter ; t != null ; t = t.getHiddenAfter() ) {
4343
hiddenAfterString.append(t.getText());
@@ -66,7 +66,7 @@ public String getHiddenBeforeString() {
6666

6767
// dump that list
6868

69-
StringBuffer hiddenBeforeString = new StringBuffer(100);
69+
StringBuilder hiddenBeforeString = new StringBuilder(100);
7070

7171
for ( CommonHiddenStreamToken t = child; t != null ;
7272
t = t.getHiddenAfter() ) {
@@ -76,31 +76,29 @@ public String getHiddenBeforeString() {
7676
return hiddenBeforeString.toString();
7777
}
7878

79-
public void xmlSerializeNode(Writer out)
80-
throws IOException {
81-
StringBuffer buf = new StringBuffer(100);
82-
buf.append("<");
83-
buf.append(getClass().getName() + " ");
84-
85-
buf.append("hiddenBeforeString=\"" +
86-
encode(getHiddenBeforeString()) +
87-
"\" text=\"" + encode(getText()) + "\" type=\"" +
88-
getType() + "\" hiddenAfterString=\"" +
89-
encode(getHiddenAfterString()) + "\"/>");
90-
out.write(buf.toString());
79+
public void xmlSerializeNode(Writer out) throws IOException {
80+
StringBuilder sb = new StringBuilder(100);
81+
sb.append("<");
82+
sb.append(getClass().getName() + " ");
83+
84+
sb.append("hiddenBeforeString=\"" +
85+
encode(getHiddenBeforeString()) +
86+
"\" text=\"" + encode(getText()) + "\" type=\"" +
87+
getType() + "\" hiddenAfterString=\"" +
88+
encode(getHiddenAfterString()) + "\"/>");
89+
out.write(sb.toString());
9190
}
9291

93-
public void xmlSerializeRootOpen(Writer out)
94-
throws IOException {
95-
StringBuffer buf = new StringBuffer(100);
96-
buf.append("<");
97-
buf.append(getClass().getName() + " ");
98-
buf.append("hiddenBeforeString=\"" +
99-
encode(getHiddenBeforeString()) +
100-
"\" text=\"" + encode(getText()) + "\" type=\"" +
101-
getType() + "\" hiddenAfterString=\"" +
102-
encode(getHiddenAfterString()) + "\">\n");
103-
out.write(buf.toString());
92+
public void xmlSerializeRootOpen(Writer out) throws IOException {
93+
StringBuilder sb = new StringBuilder(100);
94+
sb.append("<");
95+
sb.append(getClass().getName() + " ");
96+
sb.append("hiddenBeforeString=\"" +
97+
encode(getHiddenBeforeString()) +
98+
"\" text=\"" + encode(getText()) + "\" type=\"" +
99+
getType() + "\" hiddenAfterString=\"" +
100+
encode(getHiddenAfterString()) + "\">\n");
101+
out.write(sb.toString());
104102
}
105103

106104
public void xmlSerializeRootClose(Writer out)

app/src/processing/app/Base.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,17 +2780,12 @@ public boolean accept(File dir, String name) {
27802780
static public String contentsToClassPath(File folder) {
27812781
if (folder == null) return "";
27822782

2783-
StringBuffer abuffer = new StringBuffer();
2783+
StringBuilder sb = new StringBuilder();
27842784
String sep = System.getProperty("path.separator");
27852785

27862786
try {
27872787
String path = folder.getCanonicalPath();
27882788

2789-
// disabled as of 0136
2790-
// add the folder itself in case any unzipped files
2791-
// abuffer.append(sep);
2792-
// abuffer.append(path);
2793-
//
27942789
// When getting the name of this folder, make sure it has a slash
27952790
// after it, so that the names of sub-items can be added.
27962791
if (!path.endsWith(File.separator)) {
@@ -2805,17 +2800,15 @@ static public String contentsToClassPath(File folder) {
28052800

28062801
if (list[i].toLowerCase().endsWith(".jar") ||
28072802
list[i].toLowerCase().endsWith(".zip")) {
2808-
abuffer.append(sep);
2809-
abuffer.append(path);
2810-
abuffer.append(list[i]);
2803+
sb.append(sep);
2804+
sb.append(path);
2805+
sb.append(list[i]);
28112806
}
28122807
}
28132808
} catch (IOException e) {
28142809
e.printStackTrace(); // this would be odd
28152810
}
2816-
//System.out.println("included path is " + abuffer.toString());
2817-
//packageListFromClassPath(abuffer.toString()); // WHY?
2818-
return abuffer.toString();
2811+
return sb.toString();
28192812
}
28202813

28212814

app/src/processing/app/Sketch.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,24 +1570,24 @@ static final boolean asciiLetter(char c) {
15701570
*/
15711571
static public String sanitizeName(String origName) {
15721572
char orig[] = origName.toCharArray();
1573-
StringBuffer buffer = new StringBuffer();
1573+
StringBuilder sb = new StringBuilder();
15741574

15751575
// Can't lead with a digit (or anything besides a letter), so prefix with
15761576
// "sketch_". In 1.x this prefixed with an underscore, but those get shaved
15771577
// off later, since you can't start a sketch name with underscore anymore.
15781578
if (!asciiLetter(orig[0])) {
1579-
buffer.append("sketch_");
1579+
sb.append("sketch_");
15801580
}
15811581
// for (int i = 0; i < orig.length; i++) {
15821582
for (char c : orig) {
15831583
if (asciiLetter(c) || (c >= '0' && c <= '9')) {
1584-
buffer.append(c);
1584+
sb.append(c);
15851585

15861586
} else {
15871587
// Tempting to only add if prev char is not underscore, but that
15881588
// might be more confusing if lots of chars are converted and the
15891589
// result is a very short string thats nothing like the original.
1590-
buffer.append('_');
1590+
sb.append('_');
15911591
}
15921592
}
15931593
// Let's not be ridiculous about the length of filenames.
@@ -1596,22 +1596,22 @@ static public String sanitizeName(String origName) {
15961596
// Limiting to that for sketches would mean setting the
15971597
// upper-bound on the character limit here to 25 characters
15981598
// (to handle the base name + ".class")
1599-
if (buffer.length() > 63) {
1600-
buffer.setLength(63);
1599+
if (sb.length() > 63) {
1600+
sb.setLength(63);
16011601
}
16021602
// Remove underscores from the beginning, these seem to be a reserved
16031603
// thing on Android, plus it sometimes causes trouble elsewhere.
16041604
int underscore = 0;
1605-
while (underscore < buffer.length() && buffer.charAt(underscore) == '_') {
1605+
while (underscore < sb.length() && sb.charAt(underscore) == '_') {
16061606
underscore++;
16071607
}
1608-
if (underscore == buffer.length()) {
1608+
if (underscore == sb.length()) {
16091609
return "bad_sketch_name_please_fix";
16101610

16111611
} else if (underscore != 0) {
1612-
return buffer.substring(underscore);
1612+
return sb.substring(underscore);
16131613
}
1614-
return buffer.toString();
1614+
return sb.toString();
16151615
}
16161616

16171617

app/src/processing/app/exec/ProcessHelper.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ public ProcessHelper(File dir, final String... cmd) {
5050

5151
@Override
5252
public String toString() {
53-
/*
54-
final StringBuffer buffer = new StringBuffer();
55-
for (int i = 0; i < cmd.length; i++) {
56-
if (i != 0) {
57-
buffer.append(' ');
58-
}
59-
buffer.append(cmd[i]);
60-
}
61-
return buffer.toString();
62-
*/
63-
// return exe + " " + PApplet.join(args, " ");
6453
return PApplet.join(cmd, " ");
6554
}
6655

@@ -143,4 +132,4 @@ static public boolean ffs(final String... cmd) {
143132
}
144133
return false;
145134
}
146-
}
135+
}

app/src/processing/app/syntax/InputHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,10 @@ public void actionPerformed(ActionEvent evt)
11511151

11521152
if(textArea.isEditable())
11531153
{
1154-
StringBuffer buf = new StringBuffer();
1154+
StringBuilder sb = new StringBuilder();
11551155
for(int i = 0; i < repeatCount; i++)
1156-
buf.append(str);
1157-
textArea.overwriteSetSelectedText(buf.toString());
1156+
sb.append(str);
1157+
textArea.overwriteSetSelectedText(sb.toString());
11581158
}
11591159
else
11601160
{

app/src/processing/app/syntax/JEditTextArea.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ public final String getSelectedText()
13971397
start = tmp;
13981398
}
13991399

1400-
StringBuffer buf = new StringBuffer();
1400+
StringBuilder sb = new StringBuilder();
14011401
Segment seg = new Segment();
14021402

14031403
for(int i = selectionStartLine; i <= selectionEndLine; i++)
@@ -1411,13 +1411,13 @@ public final String getSelectedText()
14111411
lineLen = Math.min(end - start,lineEnd - lineStart);
14121412

14131413
getText(lineStart,lineLen,seg);
1414-
buf.append(seg.array,seg.offset,seg.count);
1414+
sb.append(seg.array,seg.offset,seg.count);
14151415

14161416
if(i != selectionEndLine)
1417-
buf.append('\n');
1417+
sb.append('\n');
14181418
}
14191419

1420-
return buf.toString();
1420+
return sb.toString();
14211421
}
14221422
else
14231423
{
@@ -1691,11 +1691,11 @@ public void copy() {
16911691
String selection = getSelectedText();
16921692

16931693
int repeatCount = inputHandler.getRepeatCount();
1694-
StringBuffer buf = new StringBuffer();
1694+
StringBuilder sb = new StringBuilder();
16951695
for(int i = 0; i < repeatCount; i++)
1696-
buf.append(selection);
1696+
sb.append(selection);
16971697

1698-
clipboard.setContents(new StringSelection(buf.toString()),null);
1698+
clipboard.setContents(new StringSelection(sb.toString()), null);
16991699
}
17001700
}
17011701

@@ -1721,7 +1721,7 @@ public void copy() {
17211721
* specific to any language or version of the PDE.
17221722
*/
17231723
public void copyAsHTML() {
1724-
StringBuffer cf = new StringBuffer("<html><body><pre>\n");
1724+
StringBuilder cf = new StringBuilder("<html><body><pre>\n");
17251725

17261726
int selStart = getSelectionStart();
17271727
int selStop = getSelectionStop();
@@ -1758,7 +1758,7 @@ public void lostOwnership(Clipboard clipboard, Transferable contents) {
17581758
}
17591759

17601760

1761-
private void emitAsHTML(StringBuffer cf, int line) {
1761+
private void emitAsHTML(StringBuilder cf, int line) {
17621762
Segment segment = new Segment();
17631763
getLineText(line, segment);
17641764

@@ -1839,7 +1839,7 @@ private void emitAsHTML(StringBuffer cf, int line) {
18391839
/**
18401840
* Handle encoding HTML entities for lt, gt, and anything non-ASCII.
18411841
*/
1842-
private void appendAsHTML(StringBuffer buffer, char c) {
1842+
private void appendAsHTML(StringBuilder buffer, char c) {
18431843
if (c == '<') {
18441844
buffer.append("&lt;");
18451845
} else if (c == '>') {
@@ -1903,11 +1903,11 @@ public void paste() {
19031903
}
19041904

19051905
int repeatCount = inputHandler.getRepeatCount();
1906-
StringBuffer buf = new StringBuffer();
1906+
StringBuilder sb = new StringBuilder();
19071907
for (int i = 0; i < repeatCount; i++) {
1908-
buf.append(selection);
1908+
sb.append(selection);
19091909
}
1910-
selection = buf.toString();
1910+
selection = sb.toString();
19111911
setSelectedText(selection);
19121912

19131913
} catch (Exception e) {

app/src/processing/app/syntax/im/CompositionTextManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void processCompositionText(AttributedCharacterIterator text, int committ
9494
CompositionTextPainter compositionPainter = textArea.getPainter().getCompositionTextpainter();
9595
compositionPainter.setComposedTextLayout(getTextLayout(text, committed_count), layoutCaretPosition);
9696
int textLength = text.getEndIndex() - text.getBeginIndex() - committed_count;
97-
StringBuffer unCommitedStringBuf = new StringBuffer(textLength);
97+
StringBuilder unCommitedStringBuf = new StringBuilder(textLength);
9898
char c;
9999
for (c = text.setIndex(committed_count); c != CharacterIterator.DONE
100100
&& textLength > 0; c = text.next(), --textLength) {

app/src/processing/mode/java/Compiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ static public boolean compile(JavaBuild build) throws SketchException {
103103
// PApplet.println(command);
104104

105105
try {
106-
// Load errors into a local StringBuffer
107-
final StringBuffer errorBuffer = new StringBuffer();
106+
// Load errors into a local StringBuilder
107+
final StringBuilder errorBuffer = new StringBuilder();
108108

109109
// Create single method dummy writer class to slurp errors from ecj
110110
Writer internalWriter = new Writer() {

app/src/processing/mode/java/JavaBuild.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public String preprocess(File srcFolder,
234234
// 1. concatenate all .pde files to the 'main' pde
235235
// store line number for starting point of each code bit
236236

237-
StringBuffer bigCode = new StringBuffer();
237+
StringBuilder bigCode = new StringBuilder();
238238
int bigCount = 0;
239239
for (SketchCode sc : sketch.getCode()) {
240240
if (sc.isExtension("pde")) {
@@ -1417,7 +1417,7 @@ protected boolean exportApplication(File destFolder,
14171417

14181418
String jarList[] = new String[jarListVector.size()];
14191419
jarListVector.copyInto(jarList);
1420-
StringBuffer exportClassPath = new StringBuffer();
1420+
StringBuilder exportClassPath = new StringBuilder();
14211421

14221422
if (exportPlatform == PConstants.MACOSX) {
14231423
for (int i = 0; i < jarList.length; i++) {
@@ -1474,7 +1474,7 @@ protected boolean exportApplication(File destFolder,
14741474
String lines[] = PApplet.loadStrings(plistTemplate);
14751475
for (int i = 0; i < lines.length; i++) {
14761476
if (lines[i].indexOf("@@") != -1) {
1477-
StringBuffer sb = new StringBuffer(lines[i]);
1477+
StringBuilder sb = new StringBuilder(lines[i]);
14781478
int index = 0;
14791479
while ((index = sb.indexOf("@@jvm_runtime@@")) != -1) {
14801480
sb.replace(index, index + "@@jvm_runtime@@".length(),

app/src/processing/mode/java/JavaEditor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -791,15 +791,15 @@ public void handleImportLibrary(String jarPath) {
791791
// statement is already in there, but if the user has the import
792792
// commented out, then this will be a problem.
793793
String[] list = Base.packageListFromClassPath(jarPath);
794-
StringBuffer buffer = new StringBuffer();
794+
StringBuilder sb = new StringBuilder();
795795
for (int i = 0; i < list.length; i++) {
796-
buffer.append("import ");
797-
buffer.append(list[i]);
798-
buffer.append(".*;\n");
796+
sb.append("import ");
797+
sb.append(list[i]);
798+
sb.append(".*;\n");
799799
}
800-
buffer.append('\n');
801-
buffer.append(getText());
802-
setText(buffer.toString());
800+
sb.append('\n');
801+
sb.append(getText());
802+
setText(sb.toString());
803803
setSelection(0, 0); // scroll to start
804804
sketch.setModified(true);
805805
}

0 commit comments

Comments
 (0)