brotli 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis.yml +11 -3
  4. data/Gemfile +2 -0
  5. data/ext/brotli/brotli.c +279 -0
  6. data/ext/brotli/brotli.h +2 -0
  7. data/ext/brotli/buffer.c +95 -0
  8. data/ext/brotli/buffer.h +19 -0
  9. data/ext/brotli/extconf.rb +21 -81
  10. data/lib/brotli/version.rb +1 -1
  11. data/vendor/brotli/dec/bit_reader.c +5 -5
  12. data/vendor/brotli/dec/bit_reader.h +15 -15
  13. data/vendor/brotli/dec/context.h +1 -1
  14. data/vendor/brotli/dec/decode.c +433 -348
  15. data/vendor/brotli/dec/decode.h +74 -48
  16. data/vendor/brotli/dec/huffman.c +5 -4
  17. data/vendor/brotli/dec/huffman.h +4 -4
  18. data/vendor/brotli/dec/port.h +2 -95
  19. data/vendor/brotli/dec/prefix.h +5 -3
  20. data/vendor/brotli/dec/state.c +15 -27
  21. data/vendor/brotli/dec/state.h +21 -17
  22. data/vendor/brotli/dec/transform.h +1 -1
  23. data/vendor/brotli/enc/backward_references.c +892 -0
  24. data/vendor/brotli/enc/backward_references.h +85 -102
  25. data/vendor/brotli/enc/backward_references_inc.h +147 -0
  26. data/vendor/brotli/enc/bit_cost.c +35 -0
  27. data/vendor/brotli/enc/bit_cost.h +23 -121
  28. data/vendor/brotli/enc/bit_cost_inc.h +127 -0
  29. data/vendor/brotli/enc/block_encoder_inc.h +33 -0
  30. data/vendor/brotli/enc/block_splitter.c +197 -0
  31. data/vendor/brotli/enc/block_splitter.h +40 -50
  32. data/vendor/brotli/enc/block_splitter_inc.h +432 -0
  33. data/vendor/brotli/enc/brotli_bit_stream.c +1334 -0
  34. data/vendor/brotli/enc/brotli_bit_stream.h +95 -167
  35. data/vendor/brotli/enc/cluster.c +56 -0
  36. data/vendor/brotli/enc/cluster.h +23 -305
  37. data/vendor/brotli/enc/cluster_inc.h +315 -0
  38. data/vendor/brotli/enc/command.h +83 -76
  39. data/vendor/brotli/enc/compress_fragment.c +747 -0
  40. data/vendor/brotli/enc/compress_fragment.h +48 -37
  41. data/vendor/brotli/enc/compress_fragment_two_pass.c +557 -0
  42. data/vendor/brotli/enc/compress_fragment_two_pass.h +37 -26
  43. data/vendor/brotli/enc/compressor.cc +139 -0
  44. data/vendor/brotli/enc/compressor.h +146 -0
  45. data/vendor/brotli/enc/context.h +102 -96
  46. data/vendor/brotli/enc/dictionary_hash.h +9 -5
  47. data/vendor/brotli/enc/encode.c +1562 -0
  48. data/vendor/brotli/enc/encode.h +211 -199
  49. data/vendor/brotli/enc/encode_parallel.cc +161 -151
  50. data/vendor/brotli/enc/encode_parallel.h +7 -8
  51. data/vendor/brotli/enc/entropy_encode.c +501 -0
  52. data/vendor/brotli/enc/entropy_encode.h +107 -89
  53. data/vendor/brotli/enc/entropy_encode_static.h +29 -62
  54. data/vendor/brotli/enc/fast_log.h +26 -20
  55. data/vendor/brotli/enc/find_match_length.h +23 -20
  56. data/vendor/brotli/enc/hash.h +614 -871
  57. data/vendor/brotli/enc/hash_forgetful_chain_inc.h +249 -0
  58. data/vendor/brotli/enc/hash_longest_match_inc.h +241 -0
  59. data/vendor/brotli/enc/hash_longest_match_quickly_inc.h +230 -0
  60. data/vendor/brotli/enc/histogram.c +95 -0
  61. data/vendor/brotli/enc/histogram.h +49 -83
  62. data/vendor/brotli/enc/histogram_inc.h +51 -0
  63. data/vendor/brotli/enc/literal_cost.c +178 -0
  64. data/vendor/brotli/enc/literal_cost.h +16 -10
  65. data/vendor/brotli/enc/memory.c +181 -0
  66. data/vendor/brotli/enc/memory.h +62 -0
  67. data/vendor/brotli/enc/metablock.c +515 -0
  68. data/vendor/brotli/enc/metablock.h +87 -57
  69. data/vendor/brotli/enc/metablock_inc.h +183 -0
  70. data/vendor/brotli/enc/port.h +73 -47
  71. data/vendor/brotli/enc/prefix.h +34 -61
  72. data/vendor/brotli/enc/quality.h +130 -0
  73. data/vendor/brotli/enc/ringbuffer.h +137 -122
  74. data/vendor/brotli/enc/{static_dict.cc → static_dict.c} +162 -139
  75. data/vendor/brotli/enc/static_dict.h +23 -18
  76. data/vendor/brotli/enc/static_dict_lut.h +11223 -12037
  77. data/vendor/brotli/enc/streams.cc +7 -7
  78. data/vendor/brotli/enc/streams.h +32 -32
  79. data/vendor/brotli/enc/{utf8_util.cc → utf8_util.c} +22 -20
  80. data/vendor/brotli/enc/utf8_util.h +16 -9
  81. data/vendor/brotli/enc/write_bits.h +49 -43
  82. metadata +34 -25
  83. data/ext/brotli/brotli.cc +0 -181
  84. data/vendor/brotli/dec/Makefile +0 -12
  85. data/vendor/brotli/dec/dictionary.c +0 -9466
  86. data/vendor/brotli/dec/dictionary.h +0 -38
  87. data/vendor/brotli/dec/types.h +0 -38
  88. data/vendor/brotli/enc/Makefile +0 -14
  89. data/vendor/brotli/enc/backward_references.cc +0 -858
  90. data/vendor/brotli/enc/block_splitter.cc +0 -505
  91. data/vendor/brotli/enc/brotli_bit_stream.cc +0 -1181
  92. data/vendor/brotli/enc/compress_fragment.cc +0 -701
  93. data/vendor/brotli/enc/compress_fragment_two_pass.cc +0 -524
  94. data/vendor/brotli/enc/dictionary.cc +0 -9466
  95. data/vendor/brotli/enc/dictionary.h +0 -41
  96. data/vendor/brotli/enc/encode.cc +0 -1180
  97. data/vendor/brotli/enc/entropy_encode.cc +0 -480
  98. data/vendor/brotli/enc/histogram.cc +0 -67
  99. data/vendor/brotli/enc/literal_cost.cc +0 -165
  100. data/vendor/brotli/enc/metablock.cc +0 -539
  101. data/vendor/brotli/enc/transform.h +0 -248
  102. data/vendor/brotli/enc/types.h +0 -29
@@ -4,16 +4,19 @@
4
4
  See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
5
  */
6
6
 
7
- // This class models a sequence of literals and a backward reference copy.
7
+ /* This class models a sequence of literals and a backward reference copy. */
8
8
 
9
9
  #ifndef BROTLI_ENC_COMMAND_H_
10
10
  #define BROTLI_ENC_COMMAND_H_
11
11
 
12
+ #include "../common/types.h"
13
+ #include "../common/port.h"
12
14
  #include "./fast_log.h"
13
15
  #include "./prefix.h"
14
- #include "./types.h"
15
16
 
16
- namespace brotli {
17
+ #if defined(__cplusplus) || defined(c_plusplus)
18
+ extern "C" {
19
+ #endif
17
20
 
18
21
  static uint32_t kInsBase[] = { 0, 1, 2, 3, 4, 5, 6, 8, 10, 14, 18, 26, 34, 50,
19
22
  66, 98, 130, 194, 322, 578, 1090, 2114, 6210, 22594 };
@@ -24,15 +27,14 @@ static uint32_t kCopyBase[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 18, 22, 30,
24
27
  static uint32_t kCopyExtra[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
25
28
  4, 4, 5, 5, 6, 7, 8, 9, 10, 24 };
26
29
 
27
- static inline uint16_t GetInsertLengthCode(size_t insertlen) {
30
+ static BROTLI_INLINE uint16_t GetInsertLengthCode(size_t insertlen) {
28
31
  if (insertlen < 6) {
29
- return static_cast<uint16_t>(insertlen);
32
+ return (uint16_t)insertlen;
30
33
  } else if (insertlen < 130) {
31
- insertlen -= 2;
32
- uint32_t nbits = Log2FloorNonZero(insertlen) - 1u;
33
- return static_cast<uint16_t>((nbits << 1) + (insertlen >> nbits) + 2);
34
+ uint32_t nbits = Log2FloorNonZero(insertlen - 2) - 1u;
35
+ return (uint16_t)((nbits << 1) + ((insertlen - 2) >> nbits) + 2);
34
36
  } else if (insertlen < 2114) {
35
- return static_cast<uint16_t>(Log2FloorNonZero(insertlen - 66) + 10);
37
+ return (uint16_t)(Log2FloorNonZero(insertlen - 66) + 10);
36
38
  } else if (insertlen < 6210) {
37
39
  return 21u;
38
40
  } else if (insertlen < 22594) {
@@ -42,115 +44,120 @@ static inline uint16_t GetInsertLengthCode(size_t insertlen) {
42
44
  }
43
45
  }
44
46
 
45
- static inline uint16_t GetCopyLengthCode(size_t copylen) {
47
+ static BROTLI_INLINE uint16_t GetCopyLengthCode(size_t copylen) {
46
48
  if (copylen < 10) {
47
- return static_cast<uint16_t>(copylen - 2);
49
+ return (uint16_t)(copylen - 2);
48
50
  } else if (copylen < 134) {
49
- copylen -= 6;
50
- uint32_t nbits = Log2FloorNonZero(copylen) - 1u;
51
- return static_cast<uint16_t>((nbits << 1) + (copylen >> nbits) + 4);
51
+ uint32_t nbits = Log2FloorNonZero(copylen - 6) - 1u;
52
+ return (uint16_t)((nbits << 1) + ((copylen - 6) >> nbits) + 4);
52
53
  } else if (copylen < 2118) {
53
- return static_cast<uint16_t>(Log2FloorNonZero(copylen - 70) + 12);
54
+ return (uint16_t)(Log2FloorNonZero(copylen - 70) + 12);
54
55
  } else {
55
56
  return 23u;
56
57
  }
57
58
  }
58
59
 
59
- static inline uint16_t CombineLengthCodes(
60
- uint16_t inscode, uint16_t copycode, bool use_last_distance) {
60
+ static BROTLI_INLINE uint16_t CombineLengthCodes(
61
+ uint16_t inscode, uint16_t copycode, BROTLI_BOOL use_last_distance) {
61
62
  uint16_t bits64 =
62
- static_cast<uint16_t>((copycode & 0x7u) | ((inscode & 0x7u) << 3));
63
+ (uint16_t)((copycode & 0x7u) | ((inscode & 0x7u) << 3));
63
64
  if (use_last_distance && inscode < 8 && copycode < 16) {
64
65
  return (copycode < 8) ? bits64 : (bits64 | 64);
65
66
  } else {
66
- // "To convert an insert-and-copy length code to an insert length code and
67
- // a copy length code, the following table can be used"
67
+ /* "To convert an insert-and-copy length code to an insert length code and
68
+ a copy length code, the following table can be used" */
68
69
  static const uint16_t cells[9] = { 128u, 192u, 384u, 256u, 320u, 512u,
69
70
  448u, 576u, 640u };
70
71
  return cells[(copycode >> 3) + 3 * (inscode >> 3)] | bits64;
71
72
  }
72
73
  }
73
74
 
74
- static inline void GetLengthCode(size_t insertlen, size_t copylen,
75
- bool use_last_distance,
76
- uint16_t* code) {
75
+ static BROTLI_INLINE void GetLengthCode(size_t insertlen, size_t copylen,
76
+ BROTLI_BOOL use_last_distance,
77
+ uint16_t* code) {
77
78
  uint16_t inscode = GetInsertLengthCode(insertlen);
78
79
  uint16_t copycode = GetCopyLengthCode(copylen);
79
80
  *code = CombineLengthCodes(inscode, copycode, use_last_distance);
80
81
  }
81
82
 
82
- static inline uint32_t GetInsertBase(uint16_t inscode) {
83
+ static BROTLI_INLINE uint32_t GetInsertBase(uint16_t inscode) {
83
84
  return kInsBase[inscode];
84
85
  }
85
86
 
86
- static inline uint32_t GetInsertExtra(uint16_t inscode) {
87
+ static BROTLI_INLINE uint32_t GetInsertExtra(uint16_t inscode) {
87
88
  return kInsExtra[inscode];
88
89
  }
89
90
 
90
- static inline uint32_t GetCopyBase(uint16_t copycode) {
91
+ static BROTLI_INLINE uint32_t GetCopyBase(uint16_t copycode) {
91
92
  return kCopyBase[copycode];
92
93
  }
93
94
 
94
- static inline uint32_t GetCopyExtra(uint16_t copycode) {
95
+ static BROTLI_INLINE uint32_t GetCopyExtra(uint16_t copycode) {
95
96
  return kCopyExtra[copycode];
96
97
  }
97
98
 
98
- struct Command {
99
- // distance_code is e.g. 0 for same-as-last short code, or 16 for offset 1.
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));
105
- // The distance prefix and extra bits are stored in this Command as if
106
- // npostfix and ndirect were 0, they are only recomputed later after the
107
- // clustering if needed.
108
- PrefixEncodeCopyDistance(distance_code, 0, 0, &dist_prefix_, &dist_extra_);
109
- GetLengthCode(insertlen, copylen_code, dist_prefix_ == 0,
110
- &cmd_prefix_);
111
- }
99
+ typedef struct Command {
100
+ uint32_t insert_len_;
101
+ /* Stores copy_len in low 24 bits and copy_len XOR copy_code in high 8 bit. */
102
+ uint32_t copy_len_;
103
+ uint32_t dist_extra_;
104
+ uint16_t cmd_prefix_;
105
+ uint16_t dist_prefix_;
106
+ } Command;
107
+
108
+ /* distance_code is e.g. 0 for same-as-last short code, or 16 for offset 1. */
109
+ static BROTLI_INLINE void InitCommand(Command* self, size_t insertlen,
110
+ size_t copylen, size_t copylen_code, size_t distance_code) {
111
+ self->insert_len_ = (uint32_t)insertlen;
112
+ self->copy_len_ = (uint32_t)(copylen | ((copylen_code ^ copylen) << 24));
113
+ /* The distance prefix and extra bits are stored in this Command as if
114
+ npostfix and ndirect were 0, they are only recomputed later after the
115
+ clustering if needed. */
116
+ PrefixEncodeCopyDistance(
117
+ distance_code, 0, 0, &self->dist_prefix_, &self->dist_extra_);
118
+ GetLengthCode(
119
+ insertlen, copylen_code, TO_BROTLI_BOOL(self->dist_prefix_ == 0),
120
+ &self->cmd_prefix_);
121
+ }
112
122
 
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_);
117
- }
123
+ static BROTLI_INLINE void InitInsertCommand(Command* self, size_t insertlen) {
124
+ self->insert_len_ = (uint32_t)insertlen;
125
+ self->copy_len_ = 4 << 24;
126
+ self->dist_extra_ = 0;
127
+ self->dist_prefix_ = 16;
128
+ GetLengthCode(insertlen, 4, BROTLI_FALSE, &self->cmd_prefix_);
129
+ }
118
130
 
119
- uint32_t DistanceCode(void) const {
120
- if (dist_prefix_ < 16) {
121
- return dist_prefix_;
122
- }
123
- uint32_t nbits = dist_extra_ >> 24;
124
- uint32_t extra = dist_extra_ & 0xffffff;
125
- uint32_t prefix = dist_prefix_ - 12 - 2 * nbits;
131
+ static BROTLI_INLINE uint32_t CommandDistanceCode(const Command* self) {
132
+ if (self->dist_prefix_ < 16) {
133
+ return self->dist_prefix_;
134
+ } else {
135
+ uint32_t nbits = self->dist_extra_ >> 24;
136
+ uint32_t extra = self->dist_extra_ & 0xffffff;
137
+ uint32_t prefix = self->dist_prefix_ - 12u - 2u * nbits;
126
138
  return (prefix << nbits) + extra + 12;
127
139
  }
140
+ }
128
141
 
129
- uint32_t DistanceContext(void) const {
130
- uint32_t r = cmd_prefix_ >> 6;
131
- uint32_t c = cmd_prefix_ & 7;
132
- if ((r == 0 || r == 2 || r == 4 || r == 7) && (c <= 2)) {
133
- return c;
134
- }
135
- return 3;
136
- }
137
-
138
- inline uint32_t copy_len(void) const {
139
- return copy_len_ & 0xFFFFFF;
142
+ static BROTLI_INLINE uint32_t CommandDistanceContext(const Command* self) {
143
+ uint32_t r = self->cmd_prefix_ >> 6;
144
+ uint32_t c = self->cmd_prefix_ & 7;
145
+ if ((r == 0 || r == 2 || r == 4 || r == 7) && (c <= 2)) {
146
+ return c;
140
147
  }
148
+ return 3;
149
+ }
141
150
 
142
- inline uint32_t copy_len_code(void) const {
143
- return (copy_len_ & 0xFFFFFF) ^ (copy_len_ >> 24);
144
- }
151
+ static BROTLI_INLINE uint32_t CommandCopyLen(const Command* self) {
152
+ return self->copy_len_ & 0xFFFFFF;
153
+ }
145
154
 
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_;
150
- uint16_t cmd_prefix_;
151
- uint16_t dist_prefix_;
152
- };
155
+ static BROTLI_INLINE uint32_t CommandCopyLenCode(const Command* self) {
156
+ return (self->copy_len_ & 0xFFFFFF) ^ (self->copy_len_ >> 24);
157
+ }
153
158
 
154
- } // namespace brotli
159
+ #if defined(__cplusplus) || defined(c_plusplus)
160
+ } /* extern "C" */
161
+ #endif
155
162
 
156
- #endif // BROTLI_ENC_COMMAND_H_
163
+ #endif /* BROTLI_ENC_COMMAND_H_ */