brotli 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/ext/brotli/brotli.cc +114 -24
  3. data/ext/brotli/brotli.h +0 -1
  4. data/ext/brotli/extconf.rb +30 -23
  5. data/lib/brotli/version.rb +1 -1
  6. data/vendor/brotli/LICENSE +1 -1
  7. data/vendor/brotli/dec/Makefile +1 -1
  8. data/vendor/brotli/dec/bit_reader.c +3 -3
  9. data/vendor/brotli/dec/bit_reader.h +25 -27
  10. data/vendor/brotli/dec/context.h +4 -4
  11. data/vendor/brotli/dec/decode.c +410 -486
  12. data/vendor/brotli/dec/decode.h +101 -105
  13. data/vendor/brotli/dec/dictionary.c +1 -1
  14. data/vendor/brotli/dec/dictionary.h +7 -8
  15. data/vendor/brotli/dec/huffman.c +103 -105
  16. data/vendor/brotli/dec/huffman.h +18 -18
  17. data/vendor/brotli/dec/port.h +52 -40
  18. data/vendor/brotli/dec/prefix.h +2 -0
  19. data/vendor/brotli/dec/state.c +13 -19
  20. data/vendor/brotli/dec/state.h +25 -39
  21. data/vendor/brotli/dec/transform.h +38 -44
  22. data/vendor/brotli/dec/types.h +2 -2
  23. data/vendor/brotli/enc/Makefile +1 -1
  24. data/vendor/brotli/enc/backward_references.cc +455 -359
  25. data/vendor/brotli/enc/backward_references.h +79 -3
  26. data/vendor/brotli/enc/bit_cost.h +54 -32
  27. data/vendor/brotli/enc/block_splitter.cc +285 -193
  28. data/vendor/brotli/enc/block_splitter.h +4 -12
  29. data/vendor/brotli/enc/brotli_bit_stream.cc +623 -324
  30. data/vendor/brotli/enc/brotli_bit_stream.h +76 -37
  31. data/vendor/brotli/enc/cluster.h +161 -120
  32. data/vendor/brotli/enc/command.h +60 -37
  33. data/vendor/brotli/enc/compress_fragment.cc +701 -0
  34. data/vendor/brotli/enc/compress_fragment.h +47 -0
  35. data/vendor/brotli/enc/compress_fragment_two_pass.cc +524 -0
  36. data/vendor/brotli/enc/compress_fragment_two_pass.h +40 -0
  37. data/vendor/brotli/enc/compressor.h +15 -0
  38. data/vendor/brotli/enc/context.h +1 -1
  39. data/vendor/brotli/enc/dictionary.h +2 -2
  40. data/vendor/brotli/enc/encode.cc +819 -286
  41. data/vendor/brotli/enc/encode.h +38 -15
  42. data/vendor/brotli/enc/encode_parallel.cc +40 -42
  43. data/vendor/brotli/enc/entropy_encode.cc +144 -147
  44. data/vendor/brotli/enc/entropy_encode.h +32 -8
  45. data/vendor/brotli/enc/entropy_encode_static.h +572 -0
  46. data/vendor/brotli/enc/fast_log.h +7 -40
  47. data/vendor/brotli/enc/find_match_length.h +9 -9
  48. data/vendor/brotli/enc/hash.h +462 -154
  49. data/vendor/brotli/enc/histogram.cc +6 -6
  50. data/vendor/brotli/enc/histogram.h +13 -13
  51. data/vendor/brotli/enc/literal_cost.cc +45 -45
  52. data/vendor/brotli/enc/metablock.cc +92 -89
  53. data/vendor/brotli/enc/metablock.h +12 -12
  54. data/vendor/brotli/enc/port.h +7 -16
  55. data/vendor/brotli/enc/prefix.h +23 -22
  56. data/vendor/brotli/enc/ringbuffer.h +75 -29
  57. data/vendor/brotli/enc/static_dict.cc +56 -48
  58. data/vendor/brotli/enc/static_dict.h +5 -5
  59. data/vendor/brotli/enc/streams.cc +1 -1
  60. data/vendor/brotli/enc/streams.h +5 -5
  61. data/vendor/brotli/enc/transform.h +40 -35
  62. data/vendor/brotli/enc/types.h +2 -0
  63. data/vendor/brotli/enc/utf8_util.cc +3 -2
  64. data/vendor/brotli/enc/write_bits.h +6 -6
  65. metadata +9 -5
  66. data/vendor/brotli/dec/streams.c +0 -102
  67. data/vendor/brotli/dec/streams.h +0 -95
@@ -15,21 +15,21 @@
15
15
 
16
16
  namespace brotli {
17
17
 
18
- static int insbase[] = { 0, 1, 2, 3, 4, 5, 6, 8, 10, 14, 18, 26, 34, 50, 66,
19
- 98, 130, 194, 322, 578, 1090, 2114, 6210, 22594 };
20
- static int insextra[] = { 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5,
21
- 5, 6, 7, 8, 9, 10, 12, 14, 24 };
22
- static int copybase[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 18, 22, 30, 38,
23
- 54, 70, 102, 134, 198, 326, 582, 1094, 2118 };
24
- static int copyextra[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4,
25
- 4, 5, 5, 6, 7, 8, 9, 10, 24 };
26
-
27
- static inline uint16_t GetInsertLengthCode(int insertlen) {
18
+ static uint32_t kInsBase[] = { 0, 1, 2, 3, 4, 5, 6, 8, 10, 14, 18, 26, 34, 50,
19
+ 66, 98, 130, 194, 322, 578, 1090, 2114, 6210, 22594 };
20
+ static uint32_t kInsExtra[] = { 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4,
21
+ 5, 5, 6, 7, 8, 9, 10, 12, 14, 24 };
22
+ static uint32_t kCopyBase[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 18, 22, 30,
23
+ 38, 54, 70, 102, 134, 198, 326, 582, 1094, 2118 };
24
+ static uint32_t kCopyExtra[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
25
+ 4, 4, 5, 5, 6, 7, 8, 9, 10, 24 };
26
+
27
+ static inline uint16_t GetInsertLengthCode(size_t insertlen) {
28
28
  if (insertlen < 6) {
29
29
  return static_cast<uint16_t>(insertlen);
30
30
  } else if (insertlen < 130) {
31
31
  insertlen -= 2;
32
- int nbits = Log2FloorNonZero(insertlen) - 1;
32
+ uint32_t nbits = Log2FloorNonZero(insertlen) - 1u;
33
33
  return static_cast<uint16_t>((nbits << 1) + (insertlen >> nbits) + 2);
34
34
  } else if (insertlen < 2114) {
35
35
  return static_cast<uint16_t>(Log2FloorNonZero(insertlen - 66) + 10);
@@ -42,12 +42,12 @@ static inline uint16_t GetInsertLengthCode(int insertlen) {
42
42
  }
43
43
  }
44
44
 
45
- static inline uint16_t GetCopyLengthCode(int copylen) {
45
+ static inline uint16_t GetCopyLengthCode(size_t copylen) {
46
46
  if (copylen < 10) {
47
47
  return static_cast<uint16_t>(copylen - 2);
48
48
  } else if (copylen < 134) {
49
49
  copylen -= 6;
50
- int nbits = Log2FloorNonZero(copylen) - 1;
50
+ uint32_t nbits = Log2FloorNonZero(copylen) - 1u;
51
51
  return static_cast<uint16_t>((nbits << 1) + (copylen >> nbits) + 4);
52
52
  } else if (copylen < 2118) {
53
53
  return static_cast<uint16_t>(Log2FloorNonZero(copylen - 70) + 12);
@@ -71,61 +71,84 @@ static inline uint16_t CombineLengthCodes(
71
71
  }
72
72
  }
73
73
 
74
- static inline void GetLengthCode(int insertlen, int copylen,
74
+ static inline void GetLengthCode(size_t insertlen, size_t copylen,
75
75
  bool use_last_distance,
76
- uint16_t* code, uint64_t* extra) {
76
+ uint16_t* code) {
77
77
  uint16_t inscode = GetInsertLengthCode(insertlen);
78
78
  uint16_t copycode = GetCopyLengthCode(copylen);
79
- uint64_t insnumextra = insextra[inscode];
80
- uint64_t numextra = insnumextra + copyextra[copycode];
81
- uint64_t insextraval = insertlen - insbase[inscode];
82
- uint64_t copyextraval = copylen - copybase[copycode];
83
79
  *code = CombineLengthCodes(inscode, copycode, use_last_distance);
84
- *extra = (numextra << 48) | (copyextraval << insnumextra) | insextraval;
80
+ }
81
+
82
+ static inline uint32_t GetInsertBase(uint16_t inscode) {
83
+ return kInsBase[inscode];
84
+ }
85
+
86
+ static inline uint32_t GetInsertExtra(uint16_t inscode) {
87
+ return kInsExtra[inscode];
88
+ }
89
+
90
+ static inline uint32_t GetCopyBase(uint16_t copycode) {
91
+ return kCopyBase[copycode];
92
+ }
93
+
94
+ static inline uint32_t GetCopyExtra(uint16_t copycode) {
95
+ return kCopyExtra[copycode];
85
96
  }
86
97
 
87
98
  struct Command {
88
99
  // distance_code is e.g. 0 for same-as-last short code, or 16 for offset 1.
89
- Command(int insertlen, int copylen, int copylen_code, int distance_code)
90
- : insert_len_(insertlen), copy_len_(copylen) {
100
+ Command(size_t insertlen, size_t copylen, size_t copylen_code,
101
+ size_t distance_code)
102
+ : insert_len_(static_cast<uint32_t>(insertlen)) {
103
+ copy_len_ = static_cast<uint32_t>(
104
+ copylen | ((copylen_code ^ copylen) << 24));
91
105
  // The distance prefix and extra bits are stored in this Command as if
92
106
  // npostfix and ndirect were 0, they are only recomputed later after the
93
107
  // clustering if needed.
94
108
  PrefixEncodeCopyDistance(distance_code, 0, 0, &dist_prefix_, &dist_extra_);
95
109
  GetLengthCode(insertlen, copylen_code, dist_prefix_ == 0,
96
- &cmd_prefix_, &cmd_extra_);
110
+ &cmd_prefix_);
97
111
  }
98
112
 
99
- Command(int insertlen)
100
- : insert_len_(insertlen), copy_len_(0), dist_prefix_(16), dist_extra_(0) {
101
- GetLengthCode(insertlen, 4, dist_prefix_ == 0, &cmd_prefix_, &cmd_extra_);
113
+ explicit Command(size_t insertlen)
114
+ : insert_len_(static_cast<uint32_t>(insertlen))
115
+ , copy_len_(4 << 24), dist_extra_(0), dist_prefix_(16) {
116
+ GetLengthCode(insertlen, 4, dist_prefix_ == 0, &cmd_prefix_);
102
117
  }
103
118
 
104
- int DistanceCode() const {
119
+ uint32_t DistanceCode(void) const {
105
120
  if (dist_prefix_ < 16) {
106
121
  return dist_prefix_;
107
122
  }
108
- int nbits = dist_extra_ >> 24;
109
- int extra = dist_extra_ & 0xffffff;
110
- int prefix = dist_prefix_ - 12 - 2 * nbits;
123
+ uint32_t nbits = dist_extra_ >> 24;
124
+ uint32_t extra = dist_extra_ & 0xffffff;
125
+ uint32_t prefix = dist_prefix_ - 12 - 2 * nbits;
111
126
  return (prefix << nbits) + extra + 12;
112
127
  }
113
128
 
114
- int DistanceContext() const {
115
- int r = cmd_prefix_ >> 6;
116
- int c = cmd_prefix_ & 7;
129
+ uint32_t DistanceContext(void) const {
130
+ uint32_t r = cmd_prefix_ >> 6;
131
+ uint32_t c = cmd_prefix_ & 7;
117
132
  if ((r == 0 || r == 2 || r == 4 || r == 7) && (c <= 2)) {
118
133
  return c;
119
134
  }
120
135
  return 3;
121
136
  }
122
137
 
123
- int insert_len_;
124
- int copy_len_;
138
+ inline uint32_t copy_len(void) const {
139
+ return copy_len_ & 0xFFFFFF;
140
+ }
141
+
142
+ inline uint32_t copy_len_code(void) const {
143
+ return (copy_len_ & 0xFFFFFF) ^ (copy_len_ >> 24);
144
+ }
145
+
146
+ uint32_t insert_len_;
147
+ /* Stores copy_len in low 24 bits and copy_len XOR copy_code in high 8 bit. */
148
+ uint32_t copy_len_;
149
+ uint32_t dist_extra_;
125
150
  uint16_t cmd_prefix_;
126
151
  uint16_t dist_prefix_;
127
- uint64_t cmd_extra_;
128
- uint32_t dist_extra_;
129
152
  };
130
153
 
131
154
  } // namespace brotli