RFR 8037106: Optimize Arrays.asList(...).forEach
Martin Buchholz
martinrb at google.com
Fri Mar 14 15:46:35 UTC 2014
Looks good to me.
I'm willing to believe for-loop over array is as efficient as fortran-style
loop
+ for (E e : a) {
+ action.accept(e);
+ }
but then you could change the other loops as well, e.g. in indexOf
+ 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++)
On Fri, Mar 14, 2014 at 5:04 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
> Hi,
>
> This patch overrides some default methods with more optimal ones for the
> Arrays.asList implementation:
>
>
> http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8037106-arrays.asList.forEach/webrev/
>
> It required some surgical work on tests to shove in the Arrays.asList test
> case, since it is a factory method and does not support structural
> modification.
>
> There are of course other optimizations that could apply to Arrays.asList,
> namely that of sub-list, but i have left that as another future possible
> exercise (plus further work could be done to Abstract/List, including
> providing a Spliterator for List & RandomAccess).
>
> Paul.
>
More information about the core-libs-dev
mailing list