JDK-8167202 : ArrayDeque improvements
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2016-10-05
  • Updated: 2017-07-18
  • Resolved: 2016-11-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b148Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
We can make many minor improvements to ArrayDeque:

The default implementation of removeIf is O(n*m), where m is the number of elements removed.  Looks like need to add ArrayDeque.removeIf (like ArrayList.removeIf) was overlooked.  Methods removeIf, removeAll, and retainAll can share implementation.

Currently we're restricted to n^2 backing array sizes, with n^2 - 1 capacity.  We should allow any capacity and not waste an extra slot, by using a size field instead of a tail field.  No need to ever use integer division.  We can make the max capacity the maximum allowed by the JVM (Integer.MAX_VALUE - slop), as with other array-backed collections.  We should grow by 3/2 instead of 2, for sufficiently large collections.

The descending iterator implementation can share most code with ascending variant.

We can implement addAll, guaranteeing only one backing array resize.

Backing array resize can be a single Arrays.copyOf if we're lucky, and even if we're not, we can just slide the front forwards afterwards.

Iterators and spliterators should implement forAllRemaining, for efficiency.
Comments
CCC: http://ccc.us.oracle.com/8167202
31-05-2017

I'm expanding the scope of this change to a rewrite.
17-10-2016

Note also that ArrayList.removeIf can be further improved, doing the removal in a single pass instead of two passes with a BitSet. See JDK-8143577.
05-10-2016