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

ArrayDeque should use Arrays.fill() instead of for() loops

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 25
    • core-libs
    • jdk-25+22-94-g0318e49500e

    • generic
    • generic

      I happened to notice a couple of places in ArrayDeque where the code is setting a contiguous range of Object[] elements to null using a for() loop. This is done to preserve the invariant that unused elements in the array are always null.

      These clear operations should be done instead with Arrays.fill(), which is presumably faster.

      The two spots are in the methods grow() and circularClear().

            acobbs Archie Cobbs
            acobbs Archie Cobbs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: