groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Refine JavaStubGenerator to gain better IO performance
Date Tue, 12 Dec 2017 14:33:23 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 1b248d367 -> 6e2a7dda7


Refine JavaStubGenerator to gain better IO performance


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/6e2a7dda
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6e2a7dda
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6e2a7dda

Branch: refs/heads/master
Commit: 6e2a7dda757d3c88708667efebe88e50c2540f31
Parents: 1b248d3
Author: sunlan <sunlan@apache.org>
Authored: Tue Dec 12 22:32:17 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue Dec 12 22:32:17 2017 +0800

----------------------------------------------------------------------
 .../groovy/tools/javac/JavaStubGenerator.java   | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6e2a7dda/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index a8674b0..f8df25e 100644
--- a/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -50,10 +50,10 @@ import org.codehaus.groovy.tools.Utilities;
 import org.codehaus.groovy.transform.trait.Traits;
 import org.objectweb.asm.Opcodes;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -95,6 +95,7 @@ public class JavaStubGenerator {
         dir.mkdirs();
     }
 
+    private static final int DEFAULT_BUFFER_SIZE = 32 * 1024; // 32K
     public void generateClass(ClassNode classNode) throws FileNotFoundException {
         // Only attempt to render our self if our super-class is resolved, else wait for
it
         if (requireSuperResolved && !classNode.getSuperClass().isResolved()) {
@@ -113,9 +114,17 @@ public class JavaStubGenerator {
         toCompile.add(fileName);
 
         File file = new File(outputPath, fileName + ".java");
-        FileOutputStream fos = new FileOutputStream(file);
         Charset charset = Charset.forName(encoding);
-        PrintWriter out = new PrintWriter(new OutputStreamWriter(fos, charset));
+        PrintWriter out =
+                new PrintWriter(
+                        new OutputStreamWriter(
+                                new BufferedOutputStream(
+                                        new FileOutputStream(file),
+                                        DEFAULT_BUFFER_SIZE
+                                ),
+                                charset
+                        )
+                );
 
         try {
             String packageName = classNode.getPackageName();
@@ -132,11 +141,6 @@ public class JavaStubGenerator {
             } catch (Exception e) {
                 // ignore
             }
-            try {
-                fos.close();
-            } catch (IOException e) {
-                // ignore
-            }
         }
     }
 


Mime
View raw message