return write(Ptr, Size);
}
+ size_t NumBytes = OutBufEnd - OutBufCur;
+
// If the buffer is empty at this point we have a string that is larger
- // than the buffer. It's better to write it unbuffered in this case.
+ // than the buffer. Directly write the chunk that is a multiple of the
+ // preferred buffer size and put the remainder in the buffer.
if (BUILTIN_EXPECT(OutBufCur == OutBufStart, false)) {
- write_impl(Ptr, Size);
+ size_t BytesToWrite = Size - (Size % NumBytes);
+ write_impl(Ptr, BytesToWrite);
+ copy_to_buffer(Ptr + BytesToWrite, Size - BytesToWrite);
return *this;
}
// We don't have enough space in the buffer to fit the string in. Insert as
// much as possible, flush and start over with the remainder.
- size_t NumBytes = OutBufEnd - OutBufCur;
copy_to_buffer(Ptr, NumBytes);
flush_nonempty();
return write(Ptr + NumBytes, Size - NumBytes);