changeset 1039:2f2ac80b6836

7061125: Proposed javac argument processing performance improvement Reviewed-by: jjg, dlsmith, mcimadamore, forax Contributed-by: schlosna@gmail.com
author jjh
date Fri, 05 Aug 2011 11:25:41 -0700
parents ceb7ca04b7eb
children 130154dbafc8
files src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java src/share/classes/com/sun/tools/javac/main/Main.java test/tools/javac/T6358166.java test/tools/javac/T6358168.java
diffstat 4 files changed, 28 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Thu Aug 04 14:25:02 2011 -0700
+++ b/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Fri Aug 05 11:25:41 2011 -0700
@@ -158,10 +158,10 @@
         } 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;
@@ -177,6 +177,17 @@
         }
     }
 
+    <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)
--- a/src/share/classes/com/sun/tools/javac/main/Main.java	Thu Aug 04 14:25:02 2011 -0700
+++ b/src/share/classes/com/sun/tools/javac/main/Main.java	Fri Aug 05 11:25:41 2011 -0700
@@ -31,7 +31,10 @@
 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;
@@ -107,8 +110,7 @@
         }
 
         public void addFile(File f) {
-            if (!filenames.contains(f))
-                filenames.append(f);
+            filenames.add(f);
         }
 
         public void addClassName(String s) {
@@ -136,7 +138,7 @@
 
     /** 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
      */
@@ -202,7 +204,7 @@
      *  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];
@@ -294,7 +296,7 @@
             showClass(showClass);
         }
 
-        return filenames.toList();
+        return filenames;
     }
     // where
         private boolean checkDirectory(OptionName optName) {
@@ -342,7 +344,7 @@
         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;
         /*
@@ -356,7 +358,7 @@
                 return EXIT_CMDERR;
             }
 
-            List<File> files;
+            Collection<File> files;
             try {
                 files = processArgs(CommandLine.parse(args));
                 if (files == null) {
--- a/test/tools/javac/T6358166.java	Thu Aug 04 14:25:02 2011 -0700
+++ b/test/tools/javac/T6358166.java	Fri Aug 05 11:25:41 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -61,7 +61,7 @@
 
         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);
--- a/test/tools/javac/T6358168.java	Thu Aug 04 14:25:02 2011 -0700
+++ b/test/tools/javac/T6358168.java	Fri Aug 05 11:25:41 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -72,7 +72,7 @@
 
         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);
@@ -91,7 +91,7 @@
 
         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,