Optimize BitReader::SkipBits for large skips

Change-Id: Ic3a383a7112f21602755d6caa6b24b2857d62ebf
This commit is contained in:
KongQun Yang 2015-01-27 15:31:24 -08:00
parent f814ce75c3
commit 5462b350ae
1 changed files with 10 additions and 3 deletions

View File

@ -18,14 +18,21 @@ BitReader::~BitReader() {}
bool BitReader::SkipBits(int num_bits) { bool BitReader::SkipBits(int num_bits) {
DCHECK_GE(num_bits, 0); 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 // Skip any bits in the current byte waiting to be processed, then
// process full bytes until less than 8 bits remaining. // 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_bits -= num_remaining_bits_in_curr_byte_;
num_remaining_bits_in_curr_byte_ = 0; 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(); UpdateCurrByte();
// If there is no more data remaining, only return true if we // If there is no more data remaining, only return true if we