8216403: Allocate fewer EnumSets in JavacFileManager#list
authorcushon
Tue, 08 Jan 2019 17:37:57 -0800
changeset 53213 716c746165b2
parent 53212 bccff579c2ff
child 53232 32c6cc430526
8216403: Allocate fewer EnumSets in JavacFileManager#list Reviewed-by: vromero, redestad
src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Wed Jan 09 20:28:16 2019 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Tue Jan 08 17:37:57 2019 -0800
@@ -104,8 +104,8 @@
 
     private FSInfo fsInfo;
 
-    private final Set<JavaFileObject.Kind> sourceOrClass =
-        EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS);
+    private static final Set<JavaFileObject.Kind> SOURCE_OR_CLASS =
+        Set.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS);
 
     protected boolean symbolFileEnabled;
 
@@ -500,6 +500,9 @@
         }
     }
 
+    private static final Set<FileVisitOption> NO_FILE_VISIT_OPTIONS = Set.of();
+    private static final Set<FileVisitOption> FOLLOW_LINKS_OPTIONS = Set.of(FOLLOW_LINKS);
+
     private final class ArchiveContainer implements Container {
         private final Path archivePath;
         private final FileSystem fileSystem;
@@ -517,7 +520,7 @@
             }
             packages = new HashMap<>();
             for (Path root : fileSystem.getRootDirectories()) {
-                Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE,
+                Files.walkFileTree(root, NO_FILE_VISIT_OPTIONS, Integer.MAX_VALUE,
                         new SimpleFileVisitor<Path>() {
                             @Override
                             public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
@@ -548,8 +551,7 @@
                 return ;
 
             int maxDepth = (recurse ? Integer.MAX_VALUE : 1);
-            Set<FileVisitOption> opts = EnumSet.of(FOLLOW_LINKS);
-            Files.walkFileTree(resolvedSubdirectory, opts, maxDepth,
+            Files.walkFileTree(resolvedSubdirectory, FOLLOW_LINKS_OPTIONS, maxDepth,
                     new SimpleFileVisitor<Path>() {
                         @Override
                         public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
@@ -763,7 +765,7 @@
         // validateClassName(className);
         nullCheck(className);
         nullCheck(kind);
-        if (!sourceOrClass.contains(kind))
+        if (!SOURCE_OR_CLASS.contains(kind))
             throw new IllegalArgumentException("Invalid kind: " + kind);
         return getFileForInput(location, RelativeFile.forClass(className, kind));
     }
@@ -811,7 +813,7 @@
         // validateClassName(className);
         nullCheck(className);
         nullCheck(kind);
-        if (!sourceOrClass.contains(kind))
+        if (!SOURCE_OR_CLASS.contains(kind))
             throw new IllegalArgumentException("Invalid kind: " + kind);
         return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling);
     }