From 5462b350aea2c2436a42d05393bfe28d8c876ea4 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Tue, 27 Jan 2015 15:31:24 -0800 Subject: [PATCH] Optimize BitReader::SkipBits for large skips Change-Id: Ic3a383a7112f21602755d6caa6b24b2857d62ebf --- packager/media/base/bit_reader.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packager/media/base/bit_reader.cc b/packager/media/base/bit_reader.cc index 0b5e49475d..8682849a39 100644 --- a/packager/media/base/bit_reader.cc +++ b/packager/media/base/bit_reader.cc @@ -18,14 +18,21 @@ BitReader::~BitReader() {} bool BitReader::SkipBits(int num_bits) { DCHECK_GE(num_bits, 0); - DLOG_IF(INFO, num_bits > 100) - << "BitReader::SkipBits inefficient for large skips"; // Skip any bits in the current byte waiting to be processed, then // process full bytes until less than 8 bits remaining. - while (num_bits > 0 && num_bits > num_remaining_bits_in_curr_byte_) { + if (num_bits > num_remaining_bits_in_curr_byte_) { num_bits -= num_remaining_bits_in_curr_byte_; num_remaining_bits_in_curr_byte_ = 0; + + int num_bytes = num_bits / 8; + num_bits %= 8; + if (bytes_left_ < num_bytes) { + bytes_left_ = 0; + return false; + } + bytes_left_ -= num_bytes; + data_ += num_bytes; UpdateCurrByte(); // If there is no more data remaining, only return true if we