Closed Crystark closed 8 years ago
Thanks for the comment, excuse the delay! I remember going down the same train of thought myself till I had a look at the String.split
source code. You'll notice that it has special optimizations for handling simple regex patterns and in those cases doesn't call Pattern.compile
. Having said that some users might be splitting on non-simple regex patterns and would want to precompile the pattern. What about your use cases? I could modify the code so that it used the optimized simple regex path if possible (extract the code out of String.split
) and otherwise compile the Pattern once only.
Heck I'll just add an overload for specifying a Pattern
and I'll make the existing version only check for the optimisation once.
I was looking to this because i wanted to split on any line break so it's a more complex regex:
private static final Transformer<String, String> LINE_SPLITTER = Transformers.split("\\r?\\n|\\r");
The overload seems like a good option.
I've released rxjava 0.7.1 with the Pattern
overload to maven central if you'd like to review/use it.
Hi,
I was looking at
TransformerStringSplit
and noticed the use ofString.split
. Wouldn't this compile the pattern for each input String ? Or am I missing something ? An idea would be to compile the pattern int theTransformerStringSplit.split
method the usePattern.split
?Thanks