You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2015/01/26 12:51:52 UTC

[2/2] camel git commit: CAMEL-8280 Fixed the issue that CaseInsensitiveMap putAll takes lots of time

CAMEL-8280 Fixed the issue that CaseInsensitiveMap putAll takes lots of time


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

Branch: refs/heads/camel-2.13.x
Commit: ad87828b4f3ee431b93b0bd6feeb71baf44f37f2
Parents: 6968de1
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Jan 26 19:50:52 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Jan 26 19:51:37 2015 +0800

----------------------------------------------------------------------
 .../apache/camel/util/CaseInsensitiveMap.java   | 33 +++++++++++++++-----
 1 file changed, 25 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ad87828b/camel-core/src/main/java/org/apache/camel/util/CaseInsensitiveMap.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/CaseInsensitiveMap.java b/camel-core/src/main/java/org/apache/camel/util/CaseInsensitiveMap.java
index b4852d7..bafc799 100644
--- a/camel-core/src/main/java/org/apache/camel/util/CaseInsensitiveMap.java
+++ b/camel-core/src/main/java/org/apache/camel/util/CaseInsensitiveMap.java
@@ -85,17 +85,34 @@ public class CaseInsensitiveMap extends HashMap<String, Object> {
     @Override
     public synchronized void putAll(Map<? extends String, ?> map) {
         entrySetView = null;
-        if (map != null && !map.isEmpty()) {
-            for (Map.Entry<? extends String, ?> entry : map.entrySet()) {
-                String key = entry.getKey();
-                Object value = entry.getValue();
-                String s = assembleKey(key);
-                originalKeys.put(s, key);
-                super.put(s, value);
+        if (map instanceof CaseInsensitiveMap) {
+            CaseInsensitiveMap cmap = (CaseInsensitiveMap)map;
+            originalKeys.putAll(cmap.getOriginalKeys());
+            // Calling the super.putAll() is much slower in JDK 1.7
+            for (Map.Entry<String, Object> entry : cmap.superEntrySet()) {
+                super.put(entry.getKey(), entry.getValue());
+            }
+        } else {
+            if (map != null && !map.isEmpty()) {
+                for (Map.Entry<? extends String, ?> entry : map.entrySet()) {
+                    String key = entry.getKey();
+                    Object value = entry.getValue();
+                    String s = assembleKey(key);
+                    originalKeys.put(s, key);
+                    super.put(s, value);
+                }
             }
         }
     }
-
+    
+    protected synchronized Map<String, String> getOriginalKeys() {
+        return originalKeys;
+    }
+    
+    protected synchronized Set<Map.Entry<String, Object>> superEntrySet() {
+        return super.entrySet();
+    }
+ 
     @Override
     public synchronized Object remove(Object key) {
         if (key == null) {