From 1b633232127b28696186f55d3eba40ab38c54088 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Wed, 1 Apr 2015 12:47:57 -0700 Subject: [PATCH] Optimize EolAwareOutputStream for bulk output Formatting merge conflicts one byte at a time is going to be very slow when the final OutputStream is a FileOutputStream and the JVM is making system calls for each byte output. When outputting a range of bytes from a byte[] the bol (beginning of line) value only depends on the value of the last byte written. Other bytes in the array can be passed directly to the lower stream for more efficient output. Change-Id: I3415f9a390ee215210a17bb5bf39164d197e1348 --- .../src/org/eclipse/jgit/merge/EolAwareOutputStream.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/EolAwareOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/EolAwareOutputStream.java index 3fd2374f3..1ddac18e5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/EolAwareOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/EolAwareOutputStream.java @@ -84,4 +84,12 @@ class EolAwareOutputStream extends OutputStream { out.write(val); bol = (val == '\n'); } + + @Override + public void write(byte[] buf, int pos, int cnt) throws IOException { + if (cnt > 0) { + out.write(buf, pos, cnt); + bol = (buf[pos + (cnt - 1)] == '\n'); + } + } }