RFR: 8001647: In-place methods on Collection/List
Akhil Arora
akhil.arora at oracle.com
Mon Dec 10 21:31:08 PST 2012
http://cr.openjdk.java.net/~akhil/8001647.3/webrev/
- now with synchronized and unmodifiable wrappers in Collections.java
for the default methods being added
On 12/10/2012 01:48 PM, Akhil Arora wrote:
> Updated with yours and Alan's comments -
>
> http://cr.openjdk.java.net/~akhil/8001647.2/webrev/
>
> - removed null check for removeSet
> - cache this.size in removeAll, replaceAll
> (for ArrayList, Vector and CopyOnWriteArrayList)
> - calculate removeCount instead of BitCount.cardinality()
> - removed unnecessary @library from test support classes
>
> Catching IndexOOB and throwing CME in forEach/removeAll/replaceAll seems
> unecessary... did you have a use-case in mind where an IndexOOB can
> occur with these methods?
>
> Thanks
>
> On 12/08/2012 05:11 AM, Arne Siegel wrote:
>> 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