camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [2/3] camel git commit: Fix the problem of using '+' and '+=' operators to concatenate stringa in a loop.
Date Thu, 12 Oct 2017 08:31:23 GMT
Fix the problem of using '+' and '+=' operators to concatenate stringa 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/53dc6eaa
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/53dc6eaa
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/53dc6eaa

Branch: refs/heads/master
Commit: 53dc6eaa0275f213dbff24fda6c3daef556a23c1
Parents: da3cdc8
Author: Kui LIU <brucekuiliu@gmail.com>
Authored: Wed Oct 11 10:18:11 2017 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Oct 12 10:16:28 2017 +0200

----------------------------------------------------------------------
 .../camel/impl/MappedEndpointConfiguration.java |  6 ++---
 .../template/generated/ParseException.java      | 26 ++++++++++----------
 2 files changed, 16 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/53dc6eaa/camel-core/src/main/java/org/apache/camel/impl/MappedEndpointConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/MappedEndpointConfiguration.java
b/camel-core/src/main/java/org/apache/camel/impl/MappedEndpointConfiguration.java
index b11091f..adbdde1 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/MappedEndpointConfiguration.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/MappedEndpointConfiguration.java
@@ -130,10 +130,10 @@ public final class MappedEndpointConfiguration extends DefaultEndpointConfigurat
         }
 
         queryParams.sort(null);
-        String q = "";
+        StringBuilder q = new StringBuilder();
         for (String entry : queryParams) {
-            q += q.length() == 0 ? "" : "&";
-            q += entry;
+            q.append(q.length() == 0 ? "" : "&");
+            q.append(entry);
         }
 
         StringBuilder u = new StringBuilder(64);

http://git-wip-us.apache.org/repos/asf/camel/blob/53dc6eaa/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/ParseException.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/ParseException.java
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/ParseException.java
index 8c562f1..5e1fe55 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/ParseException.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/stored/template/generated/ParseException.java
@@ -102,29 +102,29 @@ public class ParseException extends Exception {
             }
             expected.append(eol).append("    ");
         }
-        String retval = "Encountered \"";
+        StringBuilder retval = new StringBuilder("Encountered \"");
         Token tok = currentToken.next;
         for (int i = 0; i < maxSize; i++) {
-            if (i != 0) retval += " ";
+            if (i != 0) retval.append(" ");
             if (tok.kind == 0) {
-                retval += tokenImage[0];
+                retval.append(tokenImage[0]);
                 break;
             }
-            retval += " " + tokenImage[tok.kind];
-            retval += " \"";
-            retval += add_escapes(tok.image);
-            retval += " \"";
+            retval.append(" ").append(tokenImage[tok.kind]);
+            retval.append(" \"");
+            retval.append(add_escapes(tok.image));
+            retval.append(" \"");
             tok = tok.next;
         }
-        retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
-        retval += "." + eol;
+        retval.append("\" at line ").append(currentToken.next.beginLine).append(", column
").append(currentToken.next.beginColumn);
+        retval.append(".").append(eol);
         if (expectedTokenSequences.length == 1) {
-            retval += "Was expecting:" + eol + "    ";
+            retval.append("Was expecting:").append(eol).append("    ");
         } else {
-            retval += "Was expecting one of:" + eol + "    ";
+            retval.append("Was expecting one of:").append(eol).append("    ");
         }
-        retval += expected.toString();
-        return retval;
+        retval.append(expected.toString());
+        return retval.toString();
     }
 
     /**


Mime
View raw message