You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2018/10/24 01:27:11 UTC

[GitHub] reta commented on a change in pull request #465: StringUtils: lazy Pattern evaluation

reta commented on a change in pull request #465: StringUtils: lazy Pattern evaluation
URL: https://github.com/apache/cxf/pull/465#discussion_r227617187
 
 

 ##########
 File path: core/src/main/java/org/apache/cxf/common/util/StringUtils.java
 ##########
 @@ -51,13 +52,13 @@ private StringUtils() {
         return split(s, regex, 0);
     }
     public static String[] split(String s, String regex, int limit) {
-        Pattern p = PATTERN_MAP.getOrDefault(regex, Pattern.compile(regex));
-        return p.split(s, limit);
+        return getPattern(regex).split(s, limit);
     }
-    
     public static Stream<String> splitAsStream(String s, String regex) {
-        Pattern p = PATTERN_MAP.getOrDefault(regex, Pattern.compile(regex));
-        return p.splitAsStream(s);
+        return getPattern(regex).splitAsStream(s);
+    }
+    static Pattern getPattern(String regex) {
+        return Optional.ofNullable(PATTERN_MAP.get(regex)).orElseGet(() -> Pattern.compile(regex));
 
 Review comment:
   May be we could use `PATTERN_MAP.computeIfAbsent(regex, r -> Pattern.compile(regex));`?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services