RFR: 8155600 - Performance optimization of Arrays.asList().iterator()

Peter Levart peter.levart at gmail.com
Thu Apr 28 14:14:02 UTC 2016



On 04/28/2016 04:08 PM, Attila Szegedi wrote:
> On Thu, Apr 28, 2016 at 3:52 PM, Aleksey Shipilev <
> aleksey.shipilev at oracle.com> wrote:
>
>>   *) next(): Missing braces in throw new NSEE() block;
>>   *) next(): Why loading this.a into local?
>
> I agree with Aleksey but I'd go as far as to say that not only this.a is
> unnecessary, but i as well. The body of next() looks too elaborate. This
> seems equivalent and concise:
>
>    if (cursor >= a.length) {
>        throw new NoSuchElementException();
>    }
>    return a[cursor++];
>
> Attila.

...except that your variant can throw ArrayIndexOutOfBoundsException (if 
used inappropriately) and Tagir's can't.

(this.a is final and doesn't need to be loaded into local).

Regards, Peter



More information about the core-libs-dev mailing list