You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/03/25 11:23:49 UTC

[6/6] camel git commit: CAMEL-5398: Optimize String.replaceAll with helper method which is faster as not using regexp.

CAMEL-5398: Optimize String.replaceAll with helper method which is faster as not using regexp.


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

Branch: refs/heads/camel-2.15.x
Commit: 3e112488b2f986a02ba723410e39434ec8b25e41
Parents: 5b80cce
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Mar 25 10:33:38 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Mar 25 11:25:45 2015 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/camel/util/EndpointHelper.java   |  2 +-
 .../java/org/apache/camel/util/IntrospectionSupport.java  |  3 ++-
 .../src/main/java/org/apache/camel/util/StringHelper.java | 10 +++++++---
 .../src/main/java/org/apache/camel/util/URISupport.java   |  3 ++-
 4 files changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3e112488/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
index 18181b3..0fd0dac 100644
--- a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
@@ -318,7 +318,7 @@ public final class EndpointHelper {
      *                                  <code>mandatory</code> is <code>true</code>.
      */
     public static <T> T resolveReferenceParameter(CamelContext context, String value, Class<T> type, boolean mandatory) {
-        String valueNoHash = value.replaceAll("#", "");
+        String valueNoHash = StringHelper.replaceAll(value, "#", "");
         if (mandatory) {
             return CamelContextHelper.mandatoryLookup(context, valueNoHash, type);
         } else {

http://git-wip-us.apache.org/repos/asf/camel/blob/3e112488/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
index 98caa8e..d04c310 100755
--- a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
@@ -497,7 +497,8 @@ public final class IntrospectionSupport {
             Object ref = value;
             // try and lookup the reference based on the method
             if (context != null && refName != null && ref == null) {
-                ref = CamelContextHelper.lookup(context, refName.replaceAll("#", ""));
+                String s = StringHelper.replaceAll(refName, "#", "");
+                ref = CamelContextHelper.lookup(context, s);
                 if (ref == null) {
                     // try the next method if nothing was found
                     continue;

http://git-wip-us.apache.org/repos/asf/camel/blob/3e112488/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
index 6b81015..e68b8bf 100644
--- a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
@@ -73,8 +73,8 @@ public final class StringHelper {
             return s;
         }
 
-        s = s.replaceAll("'", "");
-        s = s.replaceAll("\"", "");
+        s = replaceAll(s, "'", "");
+        s = replaceAll(s, "\"", "");
         return s;
     }
 
@@ -121,7 +121,11 @@ public final class StringHelper {
             return "";
         }
         // must replace amp first, so we dont replace &lt; to amp later
-        return text.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
+        text = replaceAll(text, "&", "&amp;");
+        text = replaceAll(text, "\"", "&quot;");
+        text = replaceAll(text, "<", "&lt;");
+        text = replaceAll(text, ">", "&gt;");
+        return text;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/3e112488/camel-core/src/main/java/org/apache/camel/util/URISupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/URISupport.java b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
index 5962247..02d3447 100644
--- a/camel-core/src/main/java/org/apache/camel/util/URISupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
@@ -258,7 +258,8 @@ public final class URISupport {
         name = URLDecoder.decode(name, CHARSET);
         if (!isRaw) {
             // need to replace % with %25
-            value = URLDecoder.decode(value.replaceAll("%", "%25"), CHARSET);
+            String s = StringHelper.replaceAll(value, "%", "%25");
+            value = URLDecoder.decode(s, CHARSET);
         }
 
         // does the key already exist?