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:54:54 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X d51f2bd01 -> e83b86a6c


Refine JavaStubGenerator to gain better IO performance

(cherry picked from commit 6e2a7dd)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: e83b86a6ce1721cbd4c94a8f460fbdd187c9b8d2
Parents: d51f2bd
Author: sunlan <sunlan@apache.org>
Authored: Tue Dec 12 22:32:17 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue Dec 12 22:54:50 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/e83b86a6/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 76bcb05..53522fb 100644
--- a/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -49,10 +49,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;
@@ -94,6 +94,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()) {
@@ -112,9 +113,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();
@@ -131,11 +140,6 @@ public class JavaStubGenerator {
             } catch (Exception e) {
                 // ignore
             }
-            try {
-                fos.close();
-            } catch (IOException e) {
-                // ignore
-            }
         }
     }
 


Mime
View raw message