reta commented on a change in pull request #479: String.split via fastpath 
instead of precompiled Pattern
URL: https://github.com/apache/cxf/pull/479#discussion_r239430809
 
 

 ##########
 File path: core/src/main/java/org/apache/cxf/common/util/StringUtils.java
 ##########
 @@ -26,37 +26,33 @@
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Predicate;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Stream;
 
 public final class StringUtils {
-    public static final Map<String, Pattern> PATTERN_MAP = new HashMap<>();
-    static {
-        String[] patterns = {"/", " ", ":", ",", ";", "=", "\\.", "\\+"};
-        for (String p : patterns) {
-            PATTERN_MAP.put(p, Pattern.compile(p));
-        }
-    }
+    private static final Map<String, Pattern> PATTERN_MAP = new 
ConcurrentHashMap<>();
     private static final Predicate<String> NOT_EMPTY = (String s) -> 
!s.isEmpty();
 
     private StringUtils() {
     }
 
+    /* String.split via fastpath preferred */
     public static String[] split(String s, String regex) {
         return split(s, regex, 0);
     }
+    @Deprecated
     public static String[] split(String s, String regex, int limit) {
-        Pattern p = PATTERN_MAP.getOrDefault(regex, Pattern.compile(regex));
+        Pattern p = PATTERN_MAP.computeIfAbsent(regex, key -> 
Pattern.compile(key));
 
 Review comment:
   There is an well-known issue with JDK8 related to `computeIfAbsent`, 
https://bugs.openjdk.java.net/browse/JDK-8161372, not sure if we should take 
into account or not ... 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to