Currently Set.copyOf allocates both a HashSet and a new empty array when the input collection is empty.
This patch avoids allocating anything for the case where the parameter collection's isEmpty returns true. ------------- Commit messages: - 8299444: java.util.Set.copyOf allocates needlessly for empty input collections Changes: https://git.openjdk.org/jdk/pull/11847/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=11847&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8299444 Stats: 3 lines in 1 file changed: 2 ins; 0 del; 1 mod Patch: https://git.openjdk.org/jdk/pull/11847.diff Fetch: git fetch https://git.openjdk.org/jdk pull/11847/head:pull/11847 PR: https://git.openjdk.org/jdk/pull/11847