Performance of default Spliterators
Raab, Donald [Tech]
Donald.Raab at gs.com
Thu May 9 16:53:04 PDT 2013
Apologies if this was already discussed, thought about, planned or in progress.
Right now in the build I am using (about a week old) spliterator returns the following:
default Spliterator<E> spliterator() {
return Spliterators.spliterator(this, Spliterator.ORDERED);
}
For ArrayList this is overridden to return an ArrayListSpliterator. I think there should be an instance of check in spliterator to check for RandomAccess so performance is better for other RandomAccess lists that might be implemented in other libraries. So the following code would need to be changed from this:
public static <T> Spliterator<T> spliterator(Collection<? extends T> c,
int additionalCharacteristics) {
return new IteratorSpliterator<>(Objects.requireNonNull(c),
additionalCharacteristics);
}
To this:
public static <T> Spliterator<T> spliterator(Collection<? extends T> c,
int additionalCharacteristics) {
if (c instanceof RandomAccess)
return new RandomAccessSpliterator<>(c, additionalCharacteristics);
return new IteratorSpliterator<>(Objects.requireNonNull(c),
additionalCharacteristics);
}
RandomAccessSpliterator would of course need to be implemented.
Thoughts? Make sense? Already planned?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/lambda-libs-spec-experts/attachments/20130509/1e361ba1/attachment.html
More information about the lambda-libs-spec-experts
mailing list