RFR: 8001647: In-place methods on Collection/List
Arne Siegel
v.a.ammodytes at googlemail.com
Sat Dec 8 05:11:58 PST 2012
On 7 Dec 2012 at 17:42, Akhil Arora wrote:
> As part of the Library Lambdafication, this patch adds the following
> default methods to Collections -
>
> Iterable.forEach(Block<T>)
> Collection.removeAll(Predicate<T>)
> List.sort(Comparator)
> List.replaceAll(UnaryOperator<T>)
>
> It also provides more efficient implementations of these methods for
> ArrayList, Vector and CopyOnWriteArrayList. Please review.
>
> http://cr.openjdk.java.net/~akhil/8001647.1/webrev/
>
> Thanks to the many people who have already contributed to this patch.
>
I took a look at the ArrayList implementation. To my understanding it works fine, just got a
few observations.
ArrayList.java, line 1171:
final boolean anyToRemove = (removeSet != null) && !removeSet.isEmpty();
As removeSet will never be null, this line can be simplified. This is a left-over from the
preceding implementation (see b67).
ArrayList.java, method forEach optimizes the loop by reducing the number of heap accesses:
final int size = this.size;
for (int i=0; modCount == expectedModCount && i < size; i++) {
...
This trick might also be introduced to methods removeAll and replaceAll.
In the ListIterator implementation of ArrayList, there are various appearances of the idiom:
try {
...
} catch (IndexOutOfBoundsException ex) {
throw new ConcurrentModificationException();
}
This technique might also be used in forEach, removeAll, and replaceAll (though not likely to
be of any importance).
Regards
Arne Siegel
More information about the lambda-dev
mailing list