Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8033158

Eliminate inefficient use of ArrayList.remove in Scanner

XMLWordPrintable

      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.

            dlsmith Dan Smith
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: