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 2020/02/19 11:28:35 UTC

[camel] branch master updated: camel-core optimize. Avoid object allocations for unnessary lambda abuse in util classes for URI that are frequently used.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 1186efb  camel-core optimize. Avoid object allocations for unnessary lambda abuse in util classes for URI that are frequently used.
1186efb is described below

commit 1186efb7769e1344f0d67a08ab7c4507b8cf8671
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Feb 19 12:06:36 2020 +0100

    camel-core optimize. Avoid object allocations for unnessary lambda abuse in util classes for URI that are frequently used.
---
 .../main/java/org/apache/camel/util/URIScanner.java |  9 +++------
 .../main/java/org/apache/camel/util/URISupport.java | 21 ++++++++++++---------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java b/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java
index ae590c9..f1feadd 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/URIScanner.java
@@ -23,7 +23,6 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.function.BiConsumer;
 
 import static org.apache.camel.util.URISupport.RAW_TOKEN_END;
 import static org.apache.camel.util.URISupport.RAW_TOKEN_PREFIX;
@@ -253,18 +252,16 @@ class URIScanner {
         return false;
     }
 
-    public static boolean resolveRaw(String str, BiConsumer<String, String> consumer) {
+    public static String resolveRaw(String str) {
         for (int i = 0; i < RAW_TOKEN_START.length; i++) {
             String tokenStart = RAW_TOKEN_PREFIX + RAW_TOKEN_START[i];
             String tokenEnd = String.valueOf(RAW_TOKEN_END[i]);
             if (str.startsWith(tokenStart) && str.endsWith(tokenEnd)) {
-                String raw = str.substring(tokenStart.length(), str.length() - 1);
-                consumer.accept(str, raw);
-                return true;
+                return str.substring(tokenStart.length(), str.length() - 1);
             }
         }
         // not RAW value
-        return false;
+        return null;
     }
 
 }
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
index c5dcda6..a664f87 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/URISupport.java
@@ -281,15 +281,18 @@ public final class URISupport {
                         continue;
                     }
                     String str = obj.toString();
-                    final int index = i;
-                    URIScanner.resolveRaw(str, (s, raw) -> {
+                    String raw = URIScanner.resolveRaw(str);
+                    if (raw != null) {
                         // update the string in the list
-                        list.set(index, raw);
-                    });
+                        list.set(i, raw);
+                    };
                 }
             } else {
                 String str = entry.getValue().toString();
-                URIScanner.resolveRaw(str, (s, raw) -> entry.setValue(raw));
+                String raw = URIScanner.resolveRaw(str);
+                if (raw != null) {
+                    entry.setValue(raw);
+                }
             }
         }
     }
@@ -428,13 +431,13 @@ public final class URISupport {
         }
         // only append if value is not null
         rc.append("=");
-        boolean isRaw = URIScanner.resolveRaw(value, (str, raw) -> {
+        String raw = URIScanner.resolveRaw(value);
+        if (raw != null) {
             // do not encode RAW parameters unless it has %
             // need to replace % with %25 to avoid losing "%" when decoding
-            String s = StringHelper.replaceAll(str, "%", "%25");
+            String s = StringHelper.replaceAll(value, "%", "%25");
             rc.append(s);
-        });
-        if (!isRaw) {
+        } else {
             rc.append(URLEncoder.encode(value, CHARSET));
         }
     }