Bug 1309440 - Remove unused BitBuffer methods from RiceDeltaDecoder.cpp. r?francois draft
authorCykesiopka <cykesiopka.bmo@gmail.com>
Wed, 12 Oct 2016 10:51:31 +0800
changeset 423972 701b3a87221b71ec1345f0f0bea12486269dd12c
parent 423970 65c02bf0a79284e7074214484c1f0559c6906491
child 533567 777120f3329b1b518ecc1184f0783c9a4058efac
push id32036
push usercykesiopka.bmo@gmail.com
push dateWed, 12 Oct 2016 02:52:07 +0000
reviewersfrancois
bugs1309440
milestone52.0a1
Bug 1309440 - Remove unused BitBuffer methods from RiceDeltaDecoder.cpp. r?francois MozReview-Commit-ID: GOzgd7eKILm
toolkit/components/url-classifier/RiceDeltaDecoder.cpp
--- a/toolkit/components/url-classifier/RiceDeltaDecoder.cpp
+++ b/toolkit/components/url-classifier/RiceDeltaDecoder.cpp
@@ -20,29 +20,19 @@ namespace {
  *  project authors may be found in the AUTHORS file in the root of
  *  the source tree.
  */
 
 class BitBuffer {
  public:
   BitBuffer(const uint8_t* bytes, size_t byte_count);
 
-  // Gets the current offset, in bytes/bits, from the start of the buffer. The
-  // bit offset is the offset into the current byte, in the range [0,7].
-  void GetCurrentOffset(size_t* out_byte_offset, size_t* out_bit_offset);
-
   // The remaining bits in the byte buffer.
   uint64_t RemainingBitCount() const;
 
-  // Reads byte-sized values from the buffer. Returns false if there isn't
-  // enough data left for the specified type.
-  bool ReadUInt8(uint8_t* val);
-  bool ReadUInt16(uint16_t* val);
-  bool ReadUInt32(uint32_t* val);
-
   // Reads bit-sized values from the buffer. Returns false if there isn't enough
   // data left for the specified bit count..
   bool ReadBits(uint32_t* val, size_t bit_count);
 
   // Peeks bit-sized values from the buffer. Returns false if there isn't enough
   // data left for the specified number of bits. Doesn't move the current
   // offset.
   bool PeekBits(uint32_t* val, size_t bit_count);
@@ -51,32 +41,21 @@ class BitBuffer {
   // Exponential golomb values are encoded as:
   // 1) x = source val + 1
   // 2) In binary, write [countbits(x) - 1] 1s, then x
   // To decode, we count the number of leading 1 bits, read that many + 1 bits,
   // and increment the result by 1.
   // Returns false if there isn't enough data left for the specified type, or if
   // the value wouldn't fit in a uint32_t.
   bool ReadExponentialGolomb(uint32_t* val);
-  // Reads signed exponential golomb values at the current offset. Signed
-  // exponential golomb values are just the unsigned values mapped to the
-  // sequence 0, 1, -1, 2, -2, etc. in order.
-  bool ReadSignedExponentialGolomb(int32_t* val);
 
-  // Moves current position |byte_count| bytes forward. Returns false if
-  // there aren't enough bytes left in the buffer.
-  bool ConsumeBytes(size_t byte_count);
   // Moves current position |bit_count| bits forward. Returns false if
   // there aren't enough bits left in the buffer.
   bool ConsumeBits(size_t bit_count);
 
-  // Sets the current offset to the provied byte/bit offsets. The bit
-  // offset is from the given byte, in the range [0,7].
-  bool Seek(size_t byte_offset, size_t bit_offset);
-
  protected:
   const uint8_t* const bytes_;
   // The total size of |bytes_|.
   size_t byte_count_;
   // The current offset, in bytes, from the start of |bytes_|.
   size_t byte_offset_;
   // The current offset, in bits, into the current byte.
   size_t bit_offset_;
@@ -175,40 +154,16 @@ BitBuffer::BitBuffer(const uint8_t* byte
   MOZ_ASSERT(static_cast<uint64_t>(byte_count_) <=
              std::numeric_limits<uint32_t>::max());
 }
 
 uint64_t BitBuffer::RemainingBitCount() const {
   return (static_cast<uint64_t>(byte_count_) - byte_offset_) * 8 - bit_offset_;
 }
 
-bool BitBuffer::ReadUInt8(uint8_t* val) {
-  uint32_t bit_val;
-  if (!ReadBits(&bit_val, sizeof(uint8_t) * 8)) {
-    return false;
-  }
-  MOZ_ASSERT(bit_val <= std::numeric_limits<uint8_t>::max());
-  *val = static_cast<uint8_t>(bit_val);
-  return true;
-}
-
-bool BitBuffer::ReadUInt16(uint16_t* val) {
-  uint32_t bit_val;
-  if (!ReadBits(&bit_val, sizeof(uint16_t) * 8)) {
-    return false;
-  }
-  MOZ_ASSERT(bit_val <= std::numeric_limits<uint16_t>::max());
-  *val = static_cast<uint16_t>(bit_val);
-  return true;
-}
-
-bool BitBuffer::ReadUInt32(uint32_t* val) {
-  return ReadBits(val, sizeof(uint32_t) * 8);
-}
-
 bool BitBuffer::PeekBits(uint32_t* val, size_t bit_count) {
   if (!val || bit_count > RemainingBitCount() || bit_count > 32) {
     return false;
   }
   const uint8_t* bytes = bytes_ + byte_offset_;
   size_t remaining_bits_in_current_byte = 8 - bit_offset_;
   uint32_t bits = LowestBits(*bytes++, remaining_bits_in_current_byte);
   // If we're reading fewer bits than what's left in the current byte, just
@@ -233,20 +188,16 @@ bool BitBuffer::PeekBits(uint32_t* val, 
   *val = bits;
   return true;
 }
 
 bool BitBuffer::ReadBits(uint32_t* val, size_t bit_count) {
   return PeekBits(val, bit_count) && ConsumeBits(bit_count);
 }
 
-bool BitBuffer::ConsumeBytes(size_t byte_count) {
-  return ConsumeBits(byte_count * 8);
-}
-
 bool BitBuffer::ConsumeBits(size_t bit_count) {
   if (bit_count > RemainingBitCount()) {
     return false;
   }
 
   byte_offset_ += (bit_offset_ + bit_count) / 8;
   bit_offset_ = (bit_offset_ + bit_count) % 8;
   return true;
@@ -268,41 +219,9 @@ bool BitBuffer::ReadExponentialGolomb(ui
   }
   if (!ConsumeBits(1)) {
     return false; // The stream is incorrectly terminated at '1'.
   }
 
   *val = one_bit_count;
   return true;
 }
-
-bool BitBuffer::ReadSignedExponentialGolomb(int32_t* val) {
-  uint32_t unsigned_val;
-  if (!ReadExponentialGolomb(&unsigned_val)) {
-    return false;
-  }
-  if ((unsigned_val & 1) == 0) {
-    *val = -static_cast<int32_t>(unsigned_val / 2);
-  } else {
-    *val = (unsigned_val + 1) / 2;
-  }
-  return true;
 }
-
-void BitBuffer::GetCurrentOffset(
-    size_t* out_byte_offset, size_t* out_bit_offset) {
-  MOZ_ASSERT(out_byte_offset != NULL);
-  MOZ_ASSERT(out_bit_offset != NULL);
-  *out_byte_offset = byte_offset_;
-  *out_bit_offset = bit_offset_;
-}
-
-bool BitBuffer::Seek(size_t byte_offset, size_t bit_offset) {
-  if (byte_offset > byte_count_ || bit_offset > 7 ||
-      (byte_offset == byte_count_ && bit_offset > 0)) {
-    return false;
-  }
-  byte_offset_ = byte_offset;
-  bit_offset_ = bit_offset;
-  return true;
-}
-}
-