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

java.util.Set.copyOf allocates needlessly for empty input collections

XMLWordPrintable

      For non ImmutableCollections.AbstractImmutableSets the current copyOf-method allocates both a HashSet and subsequently an empty array when the input collection is empty.

      A check for isEmpty and returning the empty immutable Set should be just fine and avoid needless allocations.

            vklang Viktor Klang
            vklang Viktor Klang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: