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

Optimize Collections.nCopies().hashCode() and equals()

    Details

    • Type: Enhancement
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      Currently Collections.nCopies().hashCode() delegates to AbstractList.hashCode() which creates an iterator and caculates the hashCode of the same element n times. An optimized implementation is possible which:

      - Doesn't create an iterator
      - Calls element.hashCode() at most once
      - Has O(log(n)) complexity

      Also specialized implementation of CopiesList.equals() is possible which at least can check whether another object is also a CopiesList (in this case, no iteration is necessary, just compare single element and size).

        Attachments

          Activity

            People

            • Assignee:
              tvaleev Tagir Valeev
              Reporter:
              tvaleev Tagir Valeev
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: