]> git.cworth.org Git - apitrace/blobdiff - thirdparty/snappy/snappy.cc
Upgrade bundled snappy to version 1.0.4.
[apitrace] / thirdparty / snappy / snappy.cc
index a591aba59458a879ce30e2d75f371af3104143f2..c79edb58a7fe50db0d35ff724d042f369fa99570 100644 (file)
@@ -294,8 +294,8 @@ static inline uint32 GetUint32AtOffset(uint64 v, int offset) {
 // Returns an "end" pointer into "op" buffer.
 // "end - op" is the compressed size of "input".
 namespace internal {
-char* CompressFragment(const char* const input,
-                       const size_t input_size,
+char* CompressFragment(const char* input,
+                       size_t input_size,
                        char* op,
                        uint16* table,
                        const int table_size) {
@@ -663,17 +663,21 @@ class SnappyDecompressor {
       }
 
       const unsigned char c = *(reinterpret_cast<const unsigned char*>(ip++));
-      const uint32 entry = char_table[c];
-      const uint32 trailer = LittleEndian::Load32(ip) & wordmask[entry >> 11];
-      ip += entry >> 11;
-      const uint32 length = entry & 0xff;
 
       if ((c & 0x3) == LITERAL) {
-        uint32 literal_length = length + trailer;
+        uint32 literal_length = c >> 2;
+        if (PREDICT_FALSE(literal_length >= 60)) {
+          // Long literal.
+          const uint32 literal_length_length = literal_length - 59;
+          literal_length =
+              LittleEndian::Load32(ip) & wordmask[literal_length_length];
+          ip += literal_length_length;
+        }
+        ++literal_length;
+
         uint32 avail = ip_limit_ - ip;
         while (avail < literal_length) {
-          bool allow_fast_path = (avail >= 16);
-          if (!writer->Append(ip, avail, allow_fast_path)) return;
+          if (!writer->Append(ip, avail, false)) return;
           literal_length -= avail;
           reader_->Skip(peeked_);
           size_t n;
@@ -689,6 +693,11 @@ class SnappyDecompressor {
         }
         ip += literal_length;
       } else {
+        const uint32 entry = char_table[c];
+        const uint32 trailer = LittleEndian::Load32(ip) & wordmask[entry >> 11];
+        const uint32 length = entry & 0xff;
+        ip += entry >> 11;
+
         // copy_offset/256 is encoded in bits 8..10.  By just fetching
         // those bits, we get copy_offset (since the bit-field starts at
         // bit 8).