Commits

jjh  committed 2f2ac80

7061125: Proposed javac argument processing performance improvement
Reviewed-by: jjg, dlsmith, mcimadamore, forax
Contributed-by: schlosna@gmail.com

  • Participants
  • Parent commits ceb7ca0
  • Branches default

Comments (0)

Files changed (4)

File src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java

         } else {
             initContext();
             compilerMain.setOptions(Options.instance(context));
-            compilerMain.filenames = new ListBuffer<File>();
-            List<File> filenames = compilerMain.processArgs(CommandLine.parse(args));
+            compilerMain.filenames = new LinkedHashSet<File>();
+            Collection<File> filenames = compilerMain.processArgs(CommandLine.parse(args));
             if (!filenames.isEmpty())
-                throw new IllegalArgumentException("Malformed arguments " + filenames.toString(" "));
+                throw new IllegalArgumentException("Malformed arguments " + toString(filenames, " "));
             compiler = JavaCompiler.instance(context);
             compiler.keepComments = true;
             compiler.genEndPos = true;
         }
     }
 
+    <T> String toString(Iterable<T> items, String sep) {
+        String currSep = "";
+        StringBuilder sb = new StringBuilder();
+        for (T item: items) {
+            sb.append(currSep);
+            sb.append(item.toString());
+            currSep = sep;
+        }
+        return sb.toString();
+    }
+
     private void initContext() {
         context.put(JavacTaskImpl.class, this);
         if (context.get(TaskListener.class) != null)

File src/share/classes/com/sun/tools/javac/main/Main.java

 import java.net.URL;
 import java.security.DigestInputStream;
 import java.security.MessageDigest;
+import java.util.Collection;
+import java.util.LinkedHashSet;
 import java.util.MissingResourceException;
+import java.util.Set;
 import javax.tools.JavaFileManager;
 import javax.tools.JavaFileObject;
 import javax.annotation.processing.Processor;
         }
 
         public void addFile(File f) {
-            if (!filenames.contains(f))
-                filenames.append(f);
+            filenames.add(f);
         }
 
         public void addClassName(String s) {
 
     /** The list of source files to process
      */
-    public ListBuffer<File> filenames = null; // XXX sb protected
+    public Set<File> filenames = null; // XXX sb protected
 
     /** List of class files names passed on the command line
      */
      *  in `options' table and return all source filenames.
      *  @param flags    The array of command line arguments.
      */
-    public List<File> processArgs(String[] flags) { // XXX sb protected
+    public Collection<File> processArgs(String[] flags) { // XXX sb protected
         int ac = 0;
         while (ac < flags.length) {
             String flag = flags[ac];
             showClass(showClass);
         }
 
-        return filenames.toList();
+        return filenames;
     }
     // where
         private boolean checkDirectory(OptionName optName) {
         if (options == null)
             options = Options.instance(context); // creates a new one
 
-        filenames = new ListBuffer<File>();
+        filenames = new LinkedHashSet<File>();
         classnames = new ListBuffer<String>();
         JavaCompiler comp = null;
         /*
                 return EXIT_CMDERR;
             }
 
-            List<File> files;
+            Collection<File> files;
             try {
                 files = processArgs(CommandLine.parse(args));
                 if (files == null) {

File test/tools/javac/T6358166.java

 /*
- * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
 
         Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
         compilerMain.setOptions(Options.instance(context));
-        compilerMain.filenames = new ListBuffer<File>();
+        compilerMain.filenames = new LinkedHashSet<File>();
         compilerMain.processArgs(args);
 
         JavaCompiler c = JavaCompiler.instance(context);

File test/tools/javac/T6358168.java

 /*
- * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
 
         Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
         compilerMain.setOptions(Options.instance(context));
-        compilerMain.filenames = new ListBuffer<File>();
+        compilerMain.filenames = new LinkedHashSet<File>();
         compilerMain.processArgs(new String[] { "-d", "." });
 
         JavaCompiler compiler = JavaCompiler.instance(context);
 
         Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
         compilerMain.setOptions(Options.instance(context));
-        compilerMain.filenames = new ListBuffer<File>();
+        compilerMain.filenames = new LinkedHashSet<File>();
         compilerMain.processArgs(new String[] {
                                      "-XprintRounds",
                                      "-processorpath", testClasses,