RFR 8037106: Optimize Arrays.asList(...).forEach (original) (raw)

Martin Buchholz martinrb at google.com
Mon Mar 17 19:13:09 UTC 2014


On Mon, Mar 17, 2014 at 11:36 AM, Ulf Zibis <Ulf.Zibis at cosoco.de> wrote:

Am 14.03.2014 16:46, schrieb Martin Buchholz: + final int size = a.length; + for (int i = 0; i < size; i++) {

I like to write this using the idiom for (int i = 0, size = ...; i < size; i++) This is not thread-proof (Given there is no: final E[] a = this.a;). If a becomes replaced concurrently while looping, size becomes invalid as length of a.

That's orthogonal, I think.

Certainly, the reflex in concurrent code is to always copy fields to locals, for both performance and correctness.



More information about the core-libs-dev mailing list