[PATCH] Inefficient ArrayList.subList().toArray() (original) (raw)

Martin Buchholz martinrb at google.com
Mon Jan 29 21:02:16 UTC 2018


I'm going to expedite this a little since we are building further changes on top.

RFR: jsr166 jdk integration 2018-02 http://cr.openjdk.java.net/~martin/webrevs/jdk/jsr166-integration/overview.html

8196207: Inefficient ArrayList.subList().toArray() http://cr.openjdk.java.net/~martin/webrevs/jdk/jsr166-integration/ArrayList-subList-toArray/index.html https://bugs.openjdk.java.net/browse/JDK-8196207

On Fri, Jan 26, 2018 at 9:12 AM, Martin Buchholz <martinrb at google.com> wrote:

It may be that array-backed lists inheriting from AbstractList is not useful except when creating a prototype (or as a way of testing AbstractList!) because a high-quality implementation should always override.

On Fri, Jan 26, 2018 at 5:31 AM, Claes Redestad <claes.redestad at oracle.com_ _> wrote:

On 2018-01-26 07:20, Martin Buchholz wrote:

It's still possible to find simple performance improvements in classes like ArrayList.

Indeed! It seems ArrayList.SubList delegates quite a few of its implementations to AbstractList and AbstractCollection, which uses iterators for things that could be done more efficiently with conventional for-loops. This includes contains, equals, hashCode, indexOf, lastIndexOf... I saw up to 7x improvements on some of these over the inherited implementations when providing specialized ones for ImmutableList.SubList as part of JDK-8193128 I'll file a bug and maybe even tinker with it when I find some time... /Claes



More information about the core-libs-dev mailing list