RFR 8037106: Optimize Arrays.asList(...).forEach
Sergey Bylokhov
Sergey.Bylokhov at oracle.com
Mon Mar 17 16:07:31 UTC 2014
On 3/17/14 7:41 PM, Paul Sandoz wrote:
> On Mar 15, 2014, at 12:17 AM, Ulf Zibis <Ulf.Zibis at CoSoCo.de> wrote:
>
>> Am 14.03.2014 17:10, schrieb Paul Sandoz:
>>>> I'm willing to believe for-loop over array is as efficient as fortran-style loop
>>>>
>>>> + for (E e : a) {
>>>> + action.accept(e);
>>>> + }
>>>>
>>> Yeah, i previously went through a whole bunch of code replacing such fortran-style loops with 'foreach' style based on automated code analysis.
>> But wouldn't this help a little more? :
>> + final E[] a = this.a;
>> + for (E e : a) {
>> + action.accept(e);
>> + }
>>
> Thanks, i changed it to that.
? Why this line is needed:
final E[] a = this.a;
Since according to specification foreach over array should be
transformed to:
JLS 14.14.2:
*T[] #a = Expression; *
L1: L2: ... Lm:
for (int #i = 0; #i < #a.length; #i++) {
VariableModifiersopt TargetType Identifier = #a[#i];
Statement
}
So your code will be transformed to:
+ final E[] a = this.a;
+ E[] #a = a;
+ for (E e : #a) {
+ action.accept(e);
+ }
Or I miss something?
>> I more like the given style with less spaces:
>> 3854 for (int i=0; i<a.length; i++)
>> It better visualizes the 3 parts of the for statement.
>>
> Subjectively that irritates my eyes :-) non-subjectively it is inconsistently applied.
>
> Paul.
--
Best regards, Sergey.
More information about the core-libs-dev
mailing list