-
Enhancement
-
Resolution: Unresolved
-
P5
-
9
When performing lookahead, the Scanner caches Tokens in an ArrayList. Then, to advance, it removes each token, in turn, from the _front_ of the ArrayList, triggering an array copy to shift every list element to the left.
if (!savedTokens.isEmpty()) token = savedTokens.remove(0);
This probably has no noticeable impact (lookaheads tend to be small, and scanning is IO-bound), but is still totally unnecessary. An ArrayDeque, which has a constant-time 'removeFirst' but otherwise shares most of the characteristics of ArrayList, would be more appropriate.
if (!savedTokens.isEmpty()) token = savedTokens.remove(0);
This probably has no noticeable impact (lookaheads tend to be small, and scanning is IO-bound), but is still totally unnecessary. An ArrayDeque, which has a constant-time 'removeFirst' but otherwise shares most of the characteristics of ArrayList, would be more appropriate.
- relates to
-
JDK-6368844 (coll) Provide scalable double-ended lists
- Open
-
JDK-8143850 (coll) retrofit ArrayDeque to implement List
- Open
-
JDK-8206122 Use Queue in place of ArrayList when need to remove first element
- Resolved