Skip to content

Commit

Permalink
Used StringBuilder instead String concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
awulder committed Aug 3, 2012
1 parent a5484a7 commit 6b9850e
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 189 deletions.
12 changes: 6 additions & 6 deletions src/fitnesse/html/HtmlTag.java
Expand Up @@ -78,10 +78,10 @@ public String getAttribute(String key) {
}

protected String makeIndent(int depth) {
String indent = "";
StringBuilder indent = new StringBuilder();
for (int i = 0; i < depth; i++)
indent += '\t';
return indent;
indent.append('\t');
return indent.toString();
}

public static class Attribute {
Expand Down Expand Up @@ -173,11 +173,11 @@ private String makeTagEnd() {
}

private String makeAttributes() {
String attributes = "";
StringBuilder attributes = new StringBuilder();
for (Attribute attribute : HtmlTag.this.attributes) {
attributes += " " + attribute.name + "=\"" + attribute.value + "\"";
attributes.append(" ").append(attribute.name).append("=\"").append(attribute.value).append("\"");
}
return attributes;
return attributes.toString();
}

private String makeTag() {
Expand Down
13 changes: 6 additions & 7 deletions src/fitnesse/responders/files/UploadResponder.java
Expand Up @@ -13,7 +13,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import util.FileUtil;
import fitnesse.FitNesseContext;
import fitnesse.authentication.AlwaysSecureOperation;
import fitnesse.authentication.SecureOperation;
Expand All @@ -22,7 +21,7 @@
import fitnesse.http.Response;
import fitnesse.http.SimpleResponse;
import fitnesse.http.UploadedFile;
import fitnesse.responders.ErrorResponder;
import util.FileUtil;

public class UploadResponder implements SecureResponder {
private static final Pattern filenamePattern = Pattern.compile("([^/\\\\]*[/\\\\])*([^/\\\\]*)");
Expand Down Expand Up @@ -90,14 +89,14 @@ public static String makeNewFilename(String filename, int copyId) {
if (parts.length == 1)
return filename + "_copy" + copyId;
else {
String newName = "";
StringBuilder newName = new StringBuilder();
for (int i = 0; i < parts.length - 1; i++) {
if (i != 0)
newName += ".";
newName += parts[i];
newName.append(".");
newName.append(parts[i]);
}
newName += "_copy" + copyId + "." + parts[parts.length - 1];
return newName;
newName.append("_copy").append(copyId).append(".").append(parts[parts.length - 1]);
return newName.toString();
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/fitnesse/responders/run/slimResponder/SlimTestSystem.java
Expand Up @@ -299,9 +299,9 @@ String processAllTablesOnPage(ReadOnlyPageData pageData) throws IOException {
testResults = pageData;

boolean runAllTablesAtOnce = false;
String htmlResults = "";
StringBuilder htmlResults = new StringBuilder();
if (runAllTablesAtOnce || (allTables.size() == 0)) {
htmlResults = processTablesAndGetHtml(allTables, START_OF_TEST, END_OF_TEST);
htmlResults.append(processTablesAndGetHtml(allTables, START_OF_TEST, END_OF_TEST));
} else {
List<SlimTable> oneTableList = new ArrayList<SlimTable>(1);
for (int index = 0; index < allTables.size(); index++) {
Expand All @@ -310,11 +310,11 @@ String processAllTablesOnPage(ReadOnlyPageData pageData) throws IOException {
SlimTable nextTable = (index + 1 < allTables.size()) ? allTables.get(index + 1) : END_OF_TEST;

oneTableList.add(theTable);
htmlResults += processTablesAndGetHtml(oneTableList, startWithTable, nextTable);
htmlResults.append(processTablesAndGetHtml(oneTableList, startWithTable, nextTable));
oneTableList.clear();
}
}
return htmlResults;
return htmlResults.toString();
}

protected abstract TableScanner scanTheTables(ReadOnlyPageData pageData);
Expand Down Expand Up @@ -505,10 +505,10 @@ public ParsedPage getPreparsedScenarioLibrary() {
}

private String getScenarioLibraryContent() {
String content = "!*> Precompiled Libraries\n\n";
content += includeUncleLibraries();
content += "*!\n";
return content;
StringBuilder content = new StringBuilder("!*> Precompiled Libraries\n\n");
content.append(includeUncleLibraries());
content.append("*!\n");
return content.toString();
}

private String includeUncleLibraries() {
Expand Down
4 changes: 2 additions & 2 deletions src/fitnesse/wikitext/parser/WikiWordPath.java
Expand Up @@ -18,8 +18,8 @@ public static boolean isWikiWord(String word) {

public static String makeWikiWord(String input) {
if (isWikiWord(input)) return input;
String base = input;
while (base.length() < 3) base += "a";
StringBuilder base = new StringBuilder(input);
while (base.length() < 3) base.append("a");
return base.substring(0, 1).toUpperCase()
+ base.substring(1, base.length() - 1).toLowerCase()
+ base.substring(base.length() - 1).toUpperCase();
Expand Down
9 changes: 5 additions & 4 deletions src/fitnesse/wikitext/test/ListTest.java
@@ -1,8 +1,9 @@
package fitnesse.wikitext.test;

import fitnesse.html.HtmlElement;
import org.junit.Test;

import fitnesse.html.HtmlElement;

public class ListTest {
@Test
public void scansLists() {
Expand Down Expand Up @@ -37,9 +38,9 @@ private String listItem(String item, int level) {
}

private String indent(int level) {
String result = "";
for (int i = 0; i < level; i++) result += "\t";
return result;
StringBuilder result = new StringBuilder();
for (int i = 0; i < level; i++) result.append("\t");
return result.toString();
}

@Test
Expand Down

0 comments on commit 6b9850e

Please sign in to comment.