Pattern.splitAsStream/asPredicate
Paul Sandoz
paul.sandoz at oracle.com
Fri Apr 26 03:37:59 PDT 2013
On Apr 24, 2013, at 7:16 PM, Remi Forax <forax at univ-mlv.fr> wrote:
> 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).
Matcher returns it too:
/**
* Returns the pattern that is interpreted by this matcher.
*
* @return The pattern for which this matcher was created
*/
public Pattern pattern() {
> To summarize, the class MatcherIterator defines 4 fields instead of 3.
>
Yes, it's an inner class, but I prefer the locality, since splitAsStream is the only method that uses the class.
> 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()) {
> ...
>
Thanks i have cleaned up that code.
Paul.
> and yes, this method is useful :)
>
> cheers,
> Rémi
>
>
>
>
>
More information about the lambda-libs-spec-observers
mailing list