diff options
author | Kenneth Heafield <github@kheafield.com> | 2015-01-22 19:42:46 +0300 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2015-01-22 19:42:46 +0300 |
commit | 769c19d10ca8e05f7e983dc4553f3c4c80968fc9 (patch) | |
tree | d3ba24b9a4e66a68eea3d6df62e879d0664f4f79 /util/fake_ofstream.hh | |
parent | 9235534269e8047942fecd6d5c3f2244485d4acd (diff) |
KenLM a6d57501dcac95a31719a8628f6cbd288f6741e2 including Marcin's fixed pruning
Diffstat (limited to 'util/fake_ofstream.hh')
-rw-r--r-- | util/fake_ofstream.hh | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/util/fake_ofstream.hh b/util/fake_ofstream.hh index eefb1edce..987fa8015 100644 --- a/util/fake_ofstream.hh +++ b/util/fake_ofstream.hh @@ -17,16 +17,15 @@ namespace util { class FakeOFStream { public: - static const std::size_t kOutBuf = 1048576; - // Does not take ownership of out. // Allows default constructor, but must call SetFD. - explicit FakeOFStream(int out = -1) - : buf_(util::MallocOrThrow(kOutBuf)), - builder_(static_cast<char*>(buf_.get()), kOutBuf), + explicit FakeOFStream(int out = -1, std::size_t buffer_size = 1048576) + : buf_(util::MallocOrThrow(buffer_size)), + builder_(static_cast<char*>(buf_.get()), buffer_size), // Mostly the default but with inf instead. And no flags. convert_(double_conversion::DoubleToStringConverter::NO_FLAGS, "inf", "NaN", 'e', -6, 21, 6, 0), - fd_(out) {} + fd_(out), + buffer_size_(buffer_size) {} ~FakeOFStream() { if (buf_.get()) Flush(); @@ -51,7 +50,7 @@ class FakeOFStream { } FakeOFStream &operator<<(StringPiece str) { - if (str.size() > kOutBuf) { + if (str.size() > buffer_size_) { Flush(); util::WriteOrThrow(fd_, str.data(), str.size()); } else { @@ -98,6 +97,7 @@ class FakeOFStream { double_conversion::StringBuilder builder_; double_conversion::DoubleToStringConverter convert_; int fd_; + const std::size_t buffer_size_; }; } // namespace |