camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: Fix the problem of using '+' and '+=' operators to concatenate strings in a loop.
Date Wed, 11 Oct 2017 07:25:24 GMT
Repository: camel
Updated Branches:
  refs/heads/master 1075ab2f8 -> de7e4bfef


Fix the problem of using '+' and '+=' operators to concatenate strings 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


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/de7e4bfe
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/de7e4bfe
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/de7e4bfe

Branch: refs/heads/master
Commit: de7e4bfef353e5db1173c1169023f5f5fc0aab11
Parents: 1075ab2
Author: Kui LIU <brucekuiliu@gmail.com>
Authored: Mon Oct 9 22:31:05 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Oct 11 09:24:19 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/component/irc/IrcConfiguration.java  | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/de7e4bfe/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
index a953abd..3680f3f 100644
--- a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
+++ b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
@@ -125,11 +125,11 @@ public class IrcConfiguration implements Cloneable {
      * Return space separated list of channel names without pwd
      */
     public String getListOfChannels() {
-        String retval = "";
+        StringBuilder retval = new StringBuilder();
         for (IrcChannel channel : channels) {
-            retval += (retval.isEmpty() ? "" : " ") + channel.getName();
+            retval.append(retval.length() == 0 ? "" : " ").append(channel.getName());
         }
-        return retval;
+        return retval.toString();
     }
 
     public void configure(String uriStr) throws URISyntaxException, UnsupportedEncodingException
 {


Mime
View raw message