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
This commit is contained in:
Shawn Pearce 2015-04-01 12:47:57 -07:00
parent bda5e76420
commit 1b63323212
1 changed files with 8 additions and 0 deletions

View File

@ -84,4 +84,12 @@ public void write(int val) throws IOException {
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');
}
}
}