RFR: 8005051: optimized defaults for Iterator.forEachRemaining

Akhil Arora akhil.arora at oracle.com
Tue Apr 23 12:14:05 PDT 2013

On 04/20/2013 01:42 PM, Ulf Zibis wrote:
> Am 20.04.2013 01:59, schrieb Akhil Arora:
>> Please review the addition of optimized defaults for Iterator's
>> forEachRemaining to ArrayList, LinkedList, Vector and
>> CopyOnWriteArrayList. The unit test has a performance comparison test
>> (disabled by default) that measures the difference between this method
>> and hasNext()/next(). Significant improvements were measured by
>> overriding the default forEachRemaining by these classes (others, not
>> so much).
>> http://cr.openjdk.java.net/~akhil/8005051.1/webrev/
> You mostly do not need "<class>.this.", e.g. in Vector:
> Compare lines 1160 <-> 1137
> Line 1165 could be:
>      final Object[] elementData = this.elementData;
> or simply
>      final Object[] elements = elementData;


> To be in line with old habits, please remove space after casts. See
> also: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6939278

I see that new code by others is using spaces after casts, so I would 
like to stick with that convention.

> For performance reasons it could be considered to make Itr final and
> copy its methods to ListItr.

That is beyond the scope of this issue, needs a new issue.

> Interesting: I ever thought, private members are always final, but here
> a private method becomes extended.
> -Ulf

More information about the lambda-dev mailing list