RFR: 8221473: Configuration::reads can use Set.copyOf

Claes Redestad claes.redestad at oracle.com
Tue Mar 26 13:33:28 UTC 2019


Hi,

replacing a lingering use of Collections.unmodifiableSet with Set.copyOf
in java.lang.module.Configuration is a small startup optimization.

Bug: https://bugs.openjdk.java.net/browse/JDK-8221473
Patch:
diff -r 5ee30b6991a7 
src/java.base/share/classes/java/lang/module/Configuration.java
--- a/src/java.base/share/classes/java/lang/module/Configuration.java 
Mon Dec 03 16:25:27 2018 +0100
+++ b/src/java.base/share/classes/java/lang/module/Configuration.java 
Tue Mar 26 14:39:16 2019 +0100
@@ -575,7 +575,10 @@
      }

      Set<ResolvedModule> reads(ResolvedModule m) {
-        return Collections.unmodifiableSet(graph.get(m));
+        // The sets stored in the graph are immutable sets, so copyOf is a
+        // cheap way to return an unmodifiable Set, while also explicitly
+        // null-checking.
+        return Set.copyOf(graph.get(m));
      }

      /**

Thanks!

/Claes


More information about the core-libs-dev mailing list