This function buffers input values 8 at a time. After seeing all 8 values, it decides whether they should be encoded as a literal or repeated run.
| 340 | /// This function buffers input values 8 at a time. After seeing all 8 values, |
| 341 | /// it decides whether they should be encoded as a literal or repeated run. |
| 342 | inline bool RleEncoder::Put(uint64_t value) { |
| 343 | DCHECK(bit_width_ == 64 || value < (1LL << bit_width_)); |
| 344 | if (UNLIKELY(buffer_full_)) return false; |
| 345 | |
| 346 | if (LIKELY(current_value_ == value |
| 347 | && repeat_count_ < std::numeric_limits<int32_t>::max())) { |
| 348 | ++repeat_count_; |
| 349 | if (repeat_count_ > 8) { |
| 350 | // This is just a continuation of the current run, no need to buffer the |
| 351 | // values. |
| 352 | // Note that this is the fast path for long repeated runs. |
| 353 | return true; |
| 354 | } |
| 355 | } else { |
| 356 | if (repeat_count_ >= 8) { |
| 357 | // We had a run that was long enough but it ended, either because of a different |
| 358 | // value or because it exceeded the maximum run length. Flush the current repeated |
| 359 | // run. |
| 360 | DCHECK_EQ(literal_count_, 0); |
| 361 | FlushRepeatedRun(); |
| 362 | } |
| 363 | repeat_count_ = 1; |
| 364 | current_value_ = value; |
| 365 | } |
| 366 | |
| 367 | buffered_values_[num_buffered_values_] = value; |
| 368 | if (++num_buffered_values_ == 8) { |
| 369 | DCHECK_EQ(literal_count_ % 8, 0); |
| 370 | FlushBufferedValues(false); |
| 371 | } |
| 372 | return true; |
| 373 | } |
| 374 | |
| 375 | inline void RleEncoder::FlushLiteralRun(bool update_indicator_byte) { |
| 376 | if (literal_indicator_byte_ == NULL) { |