| 335 | } |
| 336 | |
| 337 | void ByteOutputStream::extend(int32_t bytes) { |
| 338 | if (current_ && current_->position != current_->size) { |
| 339 | LOG(FATAL) << "Extend ByteOutputStream before range full: " |
| 340 | << current_->position << " vs. " << current_->size; |
| 341 | } |
| 342 | |
| 343 | // Check if rewriting existing content. If so, move to next range and start at |
| 344 | // 0. |
| 345 | if ((current_ != nullptr) && (current_ != &ranges_.back())) { |
| 346 | ++current_; |
| 347 | current_->position = 0; |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | ranges_.emplace_back(); |
| 352 | current_ = &ranges_.back(); |
| 353 | lastRangeEnd_ = 0; |
| 354 | arena_->newRange( |
| 355 | newRangeSize(bytes), |
| 356 | ranges_.size() == 1 ? nullptr : &ranges_[ranges_.size() - 2], |
| 357 | current_); |
| 358 | allocatedBytes_ += current_->size; |
| 359 | BOLT_CHECK_GT(allocatedBytes_, 0); |
| 360 | if (isBits_) { |
| 361 | // size and position are in units of bits for a bits stream. |
| 362 | current_->size *= 8; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | int32_t ByteOutputStream::newRangeSize(int32_t bytes) const { |
| 367 | const int32_t newSize = allocatedBytes_ + bytes; |
no test coverage detected