diff options
author | Kenneth Heafield <github@kheafield.com> | 2015-03-25 17:40:21 +0300 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2015-03-25 17:40:21 +0300 |
commit | 8b323abbca16619bfbaf32d5f9b2dcaf63457d53 (patch) | |
tree | 1e6abe31ab56935b923cbd162d4070ea40675621 /util/fake_ofstream.hh | |
parent | 1064aaacbe4e7dd0571f35ef0eba3a2efc212859 (diff) |
KenLM 240ea65a021574261a38d45eb68143f26ad177e5
Diffstat (limited to 'util/fake_ofstream.hh')
-rw-r--r-- | util/fake_ofstream.hh | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/util/fake_ofstream.hh b/util/fake_ofstream.hh index 987fa8015..8299ba9ac 100644 --- a/util/fake_ofstream.hh +++ b/util/fake_ofstream.hh @@ -36,6 +36,25 @@ class FakeOFStream { fd_ = to; } + FakeOFStream &Write(const void *data, std::size_t length) { + // Dominant case + if (static_cast<std::size_t>(builder_.size() - builder_.position()) > length) { + builder_.AddSubstring((const char*)data, length); + return *this; + } + Flush(); + if (length > buffer_size_) { + util::WriteOrThrow(fd_, data, length); + } else { + builder_.AddSubstring((const char*)data, length); + } + return *this; + } + + FakeOFStream &operator<<(StringPiece str) { + return Write(str.data(), str.size()); + } + FakeOFStream &operator<<(float value) { // Odd, but this is the largest number found in the comments. EnsureRemaining(double_conversion::DoubleToStringConverter::kMaxPrecisionDigits + 8); @@ -49,17 +68,6 @@ class FakeOFStream { return *this; } - FakeOFStream &operator<<(StringPiece str) { - if (str.size() > buffer_size_) { - Flush(); - util::WriteOrThrow(fd_, str.data(), str.size()); - } else { - EnsureRemaining(str.size()); - builder_.AddSubstring(str.data(), str.size()); - } - return *this; - } - // Inefficient! TODO: more efficient implementation FakeOFStream &operator<<(unsigned value) { return *this << boost::lexical_cast<std::string>(value); |