Browse Source

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
tags/v4.0.0.201505050340-m2
Shawn Pearce 9 years ago
parent
commit
1b63323212

+ 8
- 0
org.eclipse.jgit/src/org/eclipse/jgit/merge/EolAwareOutputStream.java View File

@@ -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');
}
}
}

Loading…
Cancel
Save