diff options
Diffstat (limited to 'src/block.h')
-rw-r--r-- | src/block.h | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/block.h b/src/block.h index 4d4ad3b..13daea1 100644 --- a/src/block.h +++ b/src/block.h @@ -24,38 +24,35 @@ class block { public: - block(): block_size_(0) { + block(): line_bytes_(0) { lines_.reserve(max_lines_per_block_); } bool empty() const { - return block_size_ == 0; - } - - bool full() const { - return lines_.size() == max_lines_per_block_; + return line_bytes_ == 0; } void add_line(std::vector<uint8_t> &&line) { assert(!line.empty()); assert(line_fits(line.size())); - block_size_ += line.size(); + line_bytes_ += line.size(); lines_.emplace_back(line); } - bool line_fits(unsigned line_size) const { - return !full() && block_size_ + line_size < max_block_size_; + bool line_fits(unsigned size) { + return lines_.size() != max_lines_per_block_ + && line_bytes_ + size < max_block_size_; } void flush(FILE *f) { if (!empty()) { fprintf(f, "%dw%c%c", - block_size_ + 2, 0, + line_bytes_ + 2, 0, static_cast<int>(lines_.size())); for (auto &line : lines_) { fwrite(line.data(), 1, line.size(), f); } - block_size_ = 0; + line_bytes_ = 0; lines_.clear(); } } @@ -65,7 +62,7 @@ class block { static const unsigned max_lines_per_block_ = 128; std::vector<std::vector<uint8_t>> lines_; - int block_size_; + int line_bytes_; }; #endif // BLOCK_H |