karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fla...@apache.org
Subject [karaf] branch master updated: Avoid intern() to reuse commons tring in SimpleFilter
Date Wed, 11 Apr 2018 09:03:22 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 2c45df8  Avoid intern() to reuse commons tring in SimpleFilter
2c45df8 is described below

commit 2c45df88f166fa0892a71f30e347a0072e6f07f2
Author: Fabian Lange <lange.fabian@gmail.com>
AuthorDate: Wed Apr 11 11:01:46 2018 +0200

    Avoid intern() to reuse commons tring in SimpleFilter
---
 .../features/internal/resolver/SimpleFilter.java   | 29 +++++++++++++---------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/SimpleFilter.java
b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/SimpleFilter.java
index 02635d4..c33bda9 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/SimpleFilter.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/SimpleFilter.java
@@ -19,12 +19,11 @@ package org.apache.karaf.features.internal.resolver;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Deque;
-import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.felix.utils.version.VersionRange;
 
@@ -43,15 +42,15 @@ public class SimpleFilter {
     /**
      * Strings which are commonly found in filter specification. We use this map as an interner.
      */
-    private static final Set<String> COMMON_STRINGS;
+    private static final ConcurrentHashMap<String, String> COMMON_STRINGS;
 
     static {
-        Set<String> s = new HashSet<>(8);
-        s.add("optional");
-        s.add("osgi.ee");
-        s.add("resolution");
-        s.add("uses");
-        s.add("version");
+        ConcurrentHashMap<String, String> s = new ConcurrentHashMap<>(8);
+        s.put("optional", "optional");
+        s.put("osgi.ee", "osgi.ee");
+        s.put("resolution", "resolution");
+        s.put("uses", "uses");
+        s.put("version", "version");
         COMMON_STRINGS = s;
     }
 
@@ -62,7 +61,7 @@ public class SimpleFilter {
     private final int op;
 
     SimpleFilter(String name, Object value, int op) {
-        this.name = internIfCommon(name);
+        this.name = reuseCommonString(name);
         this.value = value;
         this.op = op;
     }
@@ -144,8 +143,14 @@ public class SimpleFilter {
         }
     }
 
-    private static String internIfCommon(String str) {
-        return str != null && COMMON_STRINGS.contains(str) ? str.intern() : str;
+    private static String reuseCommonString(String str) {
+        if (str != null) {
+            String commonString = COMMON_STRINGS.get(str);
+            if (commonString != null) {
+                return commonString;
+            }
+        }
+        return str;
     }
 
     private static void toString(StringBuilder sb, List<?> list) {

-- 
To stop receiving notification emails like this one, please contact
flange@apache.org.

Mime
View raw message