RFR: 8005051: optimized defaults for Iterator.forEachRemaining

Ulf Zibis Ulf.Zibis at CoSoCo.de
Sat Apr 20 20:42:24 UTC 2013

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: 

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

Interesting: I ever thought, private members are always final, but here a private method becomes 


More information about the core-libs-dev mailing list