diff --git a/include/fmt/os.h b/include/fmt/os.h index 15c1326f..7f40ca34 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -18,7 +18,6 @@ #include #include #include // for strtod_l -#include #if defined __APPLE__ || defined(__FreeBSD__) # include // for LC_NUMERIC_MASK on OS X @@ -380,32 +379,28 @@ static constexpr detail::buffer_size buffer_size; class ostream : private detail::buffer { private: file file_; - size_t buffer_size_; - std::unique_ptr buffer_; void flush() { if (size() == 0) return; - file_.write(buffer_.get(), size()); + file_.write(data(), size()); clear(); } void grow(size_t) final; ostream(cstring_view path, const detail::ostream_params& params) - : file_(path, params.oflag), - buffer_size_(params.buffer_size), - buffer_(new char[params.buffer_size]) { - set(buffer_.get(), params.buffer_size); + : file_(path, params.oflag) { + set(new char[params.buffer_size], params.buffer_size); } public: - ostream(ostream&& other) - : file_(std::move(other.file_)), - buffer_size_(other.buffer_size_), - buffer_(std::move(other.buffer_)) { - other.clear(); + ostream(ostream&& other) : file_(std::move(other.file_)) { + other.set(nullptr, 0); + } + ~ostream() { + flush(); + delete[] data(); } - ~ostream() { flush(); } template friend ostream output_file(cstring_view path, T... params); diff --git a/src/os.cc b/src/os.cc index 411fcea8..ae89b9c0 100644 --- a/src/os.cc +++ b/src/os.cc @@ -315,7 +315,7 @@ long getpagesize() { } void ostream::grow(size_t) { - if (this->size() == buffer_size_) flush(); + if (this->size() == this->capacity()) flush(); } #endif // FMT_USE_FCNTL FMT_END_NAMESPACE