Pattern.splitAsStream/asPredicate
Remi Forax
forax at univ-mlv.fr
Wed Apr 24 10:16:55 PDT 2013
On 04/22/2013 06:09 PM, Paul Sandoz wrote:
> Hi,
>
> It seems useful to provide an ability to create a stream from matches of a pattern, plus as a bonus create a predicate for matches of a pattern.
>
> See below for more details:
>
> http://cr.openjdk.java.net/~psandoz/lambda/jdk-8012646/webrev/
>
> Thoughts?
>
> Paul.
>
Hi Paul,
MatcherIterator should not be a local class of splitAsStream,
because the reference to the current Pattern will be kept
even if the Matcher not reference if anymore
(note that the current implementation of the Matcher always references
the Pattern object but maybe at some point the automata will be
transformed to bytecode as by example V8 does).
To summarize, the class MatcherIterator defines 4 fields instead of 3.
The is no need to initialize current and nextElement to their default
values,
javac emits bytecodes for that.
in next(), the else is useless and it's rare in the jdk sources to find
a else after a throw.
in hasNext(), you can re-order the branch of the first test to avoid the
code to be shifted to the right.
if (nextElement != null) {
return true;
}
if (current == input.length()) {
...
and yes, this method is useful :)
cheers,
Rémi
More information about the lambda-libs-spec-experts
mailing list