Browse Source

Fix the problem of using '+=' operator to concatenate strings a in a loop.

The method is building a String using concatenation in a loop.
In each iteration, the String is converted to a StringBuilder, appended to, and converted back to a String.
This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration.
Better performance can be obtained by using a StringBuilder explicitly.
http://findbugs.sourceforge.net/bugDescriptions.html#SBSC_USE_STRINGBUFFER_CONCATENATION
master
Kui LIU Stefan Bodewig 7 years ago
parent
commit
c141ef4009
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      src/main/org/apache/tools/ant/Main.java

+ 2
- 2
src/main/org/apache/tools/ant/Main.java View File

@@ -1292,9 +1292,9 @@ public class Main implements AntMain {
// now, start printing the targets and their descriptions
final String lSep = System.getProperty("line.separator");
// got a bit annoyed that I couldn't find a pad function
String spaces = " ";
StringBuilder spaces = new StringBuilder(" ");
while (spaces.length() <= maxlen) {
spaces += spaces;
spaces.append(spaces);
}
final StringBuilder msg = new StringBuilder();
msg.append(heading).append(lSep).append(lSep);


Loading…
Cancel
Save