Repository: groovy
Updated Branches:
  refs/heads/master 3602dd940 -> 2bd6ac59a


GROOVY-8894: Improve performance of DGM `leftShift(OutputStream, 
InputStream)`(closes #826)


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

Branch: refs/heads/master
Commit: 2bd6ac59a00490fb13f52d597e7c31c616cf9c64
Parents: 3602dd9
Author: Daniel Sun <sun...@apache.org>
Authored: Tue Nov 20 21:22:28 2018 +0800
Committer: Daniel Sun <sun...@apache.org>
Committed: Tue Nov 20 21:22:28 2018 +0800

----------------------------------------------------------------------
 .../org/codehaus/groovy/runtime/IOGroovyMethods.java    | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/2bd6ac59/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java 
b/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
index f65c85f..c4e54e3 100644
--- a/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
@@ -205,14 +205,8 @@ public class IOGroovyMethods extends 
DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     public static OutputStream leftShift(OutputStream self, InputStream in) 
throws IOException {
-        byte[] buf = new byte[1024];
-        while (true) {
-            int count = in.read(buf, 0, buf.length);
-            if (count == -1) break;
-            if (count == 0) {
-                Thread.yield();
-                continue;
-            }
+        byte[] buf = new byte[DEFAULT_BUFFER_SIZE];
+        for (int count; -1 != (count = in.read(buf)); ) {
             self.write(buf, 0, count);
         }
         self.flush();
@@ -1703,4 +1697,6 @@ public class IOGroovyMethods extends 
DefaultGroovyMethodsSupport {
             writer.write(-2);  // FE
         }
     }
+
+    private static int DEFAULT_BUFFER_SIZE = 8192; // 8k
 }

Reply via email to