Use StringBuilder instead of concatenation in ReviewCommand

Coverity reports a performance issue caused by using the + operator
to concatenate strings within a loop. See CID 20069 on the coverity
scan project [1].

Refactor it to use a StringBuilder instead.

[1] https://scan.coverity.com/projects/4032

Change-Id: Ib091b3a1ac8a2404b2d68e88c17c28e31f70475c
This commit is contained in:
David Pursehouse
2015-02-04 18:05:06 +09:00
parent 3a19184672
commit 29be772d35

View File

@@ -340,15 +340,16 @@ public class ReviewCommand extends SshCommand {
}
for (LabelType type : allProjectsControl.getLabelTypes().getLabelTypes()) {
String usage;
usage = "score for " + type.getName() + "\n";
StringBuilder usage = new StringBuilder("score for ")
.append(type.getName())
.append("\n");
for (LabelValue v : type.getValues()) {
usage += v.format() + "\n";
usage.append(v.format()).append("\n");
}
final String name = "--" + type.getName().toLowerCase();
optionList.add(new ApproveOption(name, usage, type));
optionList.add(new ApproveOption(name, usage.toString(), type));
}
super.parseCommandLine();