verhas commented on a change in pull request #443: Optimize string split 
methods: 1. Use ThreadLocal to make reuse of th…
URL: https://github.com/apache/commons-lang/pull/443#discussion_r317719269
 
 

 ##########
 File path: src/main/java/org/apache/commons/lang3/StringUtils.java
 ##########
 @@ -7968,9 +7968,160 @@ public static String rotate(final String str, final 
int shift) {
             }
         }
         if (match || preserveAllTokens && lastMatch) {
-            list.add(str.substring(start, i));
+            buffer.add(str.substring(start, i));
+        }
+        return buffer.toArray();
+    }
+
+    private static final ThreadLocal<SplitBufferThreadLocalHelper> 
SPLIT_BUFFER_THREAD_LOCAL
+            = new ThreadLocal<SplitBufferThreadLocalHelper>() {
+        @Override
+        protected SplitBufferThreadLocalHelper initialValue() {
+            return new SplitBufferThreadLocalHelper();
+        }
+    };
+
+
+
+    /**
+     * Private class act as a buffer while splitting.
+     * "SplitBufferThreadLocalHelper" is constructed as a thread local 
variable so it is
 
 Review comment:
   Yes, it is thread-safe, but as soon as project loom is released 
thread-safety will not be our concerns. It will not be fiber safe. Using 
thread-local variables instead of objects is a hack and will bite back as hard 
as static variables bit our assets when we started to create multi-thread 
programs.

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


With regards,
Apache Git Services

Reply via email to