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,44 +4,39 @@
4
4
  See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
5
  */
6
6
 
7
- // Implementation of parallel Brotli compressor.
7
+ /* Implementation of parallel Brotli compressor. */
8
8
 
9
9
  #include "./encode_parallel.h"
10
10
 
11
- #include <algorithm>
12
- #include <limits>
11
+ #include <vector>
13
12
 
14
13
  #include "./backward_references.h"
15
- #include "./bit_cost.h"
16
- #include "./block_splitter.h"
17
14
  #include "./brotli_bit_stream.h"
18
- #include "./cluster.h"
19
15
  #include "./context.h"
20
- #include "./metablock.h"
21
- #include "./transform.h"
22
16
  #include "./entropy_encode.h"
23
17
  #include "./fast_log.h"
24
18
  #include "./hash.h"
25
- #include "./histogram.h"
19
+ #include "./metablock.h"
20
+ #include "./port.h"
26
21
  #include "./prefix.h"
22
+ #include "./quality.h"
27
23
  #include "./utf8_util.h"
28
- #include "./write_bits.h"
29
24
 
30
25
  namespace brotli {
31
26
 
32
27
  namespace {
33
28
 
34
- void RecomputeDistancePrefixes(Command* cmds, size_t num_commands,
35
- uint32_t num_direct_distance_codes,
36
- uint32_t distance_postfix_bits) {
29
+ static void RecomputeDistancePrefixes(Command* cmds, size_t num_commands,
30
+ uint32_t num_direct_distance_codes,
31
+ uint32_t distance_postfix_bits) {
37
32
  if (num_direct_distance_codes == 0 &&
38
33
  distance_postfix_bits == 0) {
39
34
  return;
40
35
  }
41
36
  for (size_t i = 0; i < num_commands; ++i) {
42
37
  Command* cmd = &cmds[i];
43
- if (cmd->copy_len() && cmd->cmd_prefix_ >= 128) {
44
- PrefixEncodeCopyDistance(cmd->DistanceCode(),
38
+ if (CommandCopyLen(cmd) && cmd->cmd_prefix_ >= 128) {
39
+ PrefixEncodeCopyDistance(CommandDistanceCode(cmd),
45
40
  num_direct_distance_codes,
46
41
  distance_postfix_bits,
47
42
  &cmd->dist_prefix_,
@@ -50,230 +45,245 @@ void RecomputeDistancePrefixes(Command* cmds, size_t num_commands,
50
45
  }
51
46
  }
52
47
 
53
- bool WriteMetaBlockParallel(const BrotliParams& params,
54
- const uint32_t input_size,
55
- const uint8_t* input_buffer,
56
- const uint32_t prefix_size,
57
- const uint8_t* prefix_buffer,
58
- const bool is_first,
59
- const bool is_last,
60
- size_t* encoded_size,
61
- uint8_t* encoded_buffer) {
48
+ /* Returns 1 on success, otherwise 0. */
49
+ int WriteMetaBlockParallel(const BrotliEncoderParams* params,
50
+ const uint32_t input_size,
51
+ const uint8_t* input_buffer,
52
+ const uint32_t prefix_size,
53
+ const uint8_t* prefix_buffer,
54
+ const int is_first,
55
+ const int is_last,
56
+ size_t* encoded_size,
57
+ uint8_t* encoded_buffer) {
62
58
  if (input_size == 0) {
63
- return false;
59
+ return 0;
64
60
  }
65
61
 
66
- // Copy prefix + next input block into a continuous area.
67
- uint32_t input_pos = prefix_size;
68
- // CreateBackwardReferences reads up to 3 bytes past the end of input if the
69
- // mask points past the end of input.
70
- // FindMatchLengthWithLimit could do another 8 bytes look-forward.
71
- std::vector<uint8_t> input(prefix_size + input_size + 4 + 8);
72
- memcpy(&input[0], prefix_buffer, prefix_size);
73
- memcpy(&input[input_pos], input_buffer, input_size);
74
- // Since we don't have a ringbuffer, masking is a no-op.
75
- // We use one less bit than the full range because some of the code uses
76
- // mask + 1 as the size of the ringbuffer.
77
- const uint32_t mask = std::numeric_limits<uint32_t>::max() >> 1;
78
-
79
- uint8_t prev_byte = input_pos > 0 ? input[(input_pos - 1) & mask] : 0;
80
- uint8_t prev_byte2 = input_pos > 1 ? input[(input_pos - 2) & mask] : 0;
81
-
82
- // Decide about UTF8 mode.
83
- static const double kMinUTF8Ratio = 0.75;
84
- bool utf8_mode = IsMostlyUTF8(&input[0], input_pos, mask, input_size,
85
- kMinUTF8Ratio);
86
-
87
- // Initialize hashers.
88
- int hash_type = std::min(10, params.quality);
89
- Hashers* hashers = new Hashers();
90
- hashers->Init(hash_type);
62
+ MemoryManager memory_manager;
63
+ MemoryManager* m = &memory_manager;
64
+ BrotliInitMemoryManager(m, 0, 0, 0);
91
65
 
92
- // Compute backward references.
66
+ uint8_t* storage;
67
+ size_t storage_ix;
68
+ uint8_t first_byte;
69
+ size_t first_byte_bits;
70
+ size_t output_size;
71
+ uint32_t num_direct_distance_codes;
72
+ uint32_t distance_postfix_bits;
73
+ ContextType literal_context_mode;
93
74
  size_t last_insert_len = 0;
94
75
  size_t num_commands = 0;
95
76
  size_t num_literals = 0;
96
77
  int dist_cache[4] = { -4, -4, -4, -4 };
97
- Command* commands = static_cast<Command*>(
98
- malloc(sizeof(Command) * ((input_size + 1) >> 1)));
99
- if (commands == 0) {
100
- delete hashers;
101
- return false;
102
- }
103
- CreateBackwardReferences(
104
- input_size, input_pos, is_last,
105
- &input[0], mask,
106
- params.quality,
107
- params.lgwin,
108
- hashers,
109
- hash_type,
110
- dist_cache,
111
- &last_insert_len,
112
- commands,
113
- &num_commands,
78
+ Command* commands;
79
+ Hashers* hashers;
80
+ int use_utf8_mode;
81
+ uint8_t prev_byte;
82
+ uint8_t prev_byte2;
83
+ const uint32_t mask = BROTLI_UINT32_MAX >> 1;
84
+
85
+ /* Copy prefix + next input block into a continuous area. */
86
+ uint32_t input_pos = prefix_size;
87
+ /* CreateBackwardReferences reads up to 3 bytes past the end of input if the
88
+ mask points past the end of input.
89
+ FindMatchLengthWithLimit could do another 8 bytes look-forward. */
90
+ uint8_t* input = BROTLI_ALLOC(m, uint8_t, prefix_size + input_size + 4 + 8);
91
+ if (BROTLI_IS_OOM(m)) goto oom;
92
+ memcpy(input, prefix_buffer, prefix_size);
93
+ memcpy(input + input_pos, input_buffer, input_size);
94
+ /* Since we don't have a ringbuffer, masking is a no-op.
95
+ We use one less bit than the full range because some of the code uses
96
+ mask + 1 as the size of the ringbuffer. */
97
+
98
+ prev_byte = input_pos > 0 ? input[(input_pos - 1) & mask] : 0;
99
+ prev_byte2 = input_pos > 1 ? input[(input_pos - 2) & mask] : 0;
100
+
101
+ /* Decide about UTF8 mode. */
102
+ static const double kMinUTF8Ratio = 0.75;
103
+ use_utf8_mode = BrotliIsMostlyUTF8(
104
+ input, input_pos, mask, input_size, kMinUTF8Ratio);
105
+
106
+ /* Initialize hashers. */
107
+ hashers = BROTLI_ALLOC(m, Hashers, 1);
108
+ if (BROTLI_IS_OOM(m)) goto oom;
109
+ InitHashers(hashers);
110
+ HashersSetup(m, hashers, ChooseHasher(params));
111
+ if (BROTLI_IS_OOM(m)) goto oom;
112
+
113
+ /* Compute backward references. */
114
+ commands = BROTLI_ALLOC(m, Command, ((input_size + 1) >> 1));
115
+ if (BROTLI_IS_OOM(m)) goto oom;
116
+ BrotliCreateBackwardReferences(m, input_size, input_pos,
117
+ TO_BROTLI_BOOL(is_last), input, mask, params,
118
+ hashers, dist_cache, &last_insert_len, commands, &num_commands,
114
119
  &num_literals);
115
- delete hashers;
120
+ if (BROTLI_IS_OOM(m)) goto oom;
121
+ DestroyHashers(m, hashers);
122
+ BROTLI_FREE(m, hashers);
116
123
  if (last_insert_len > 0) {
117
- commands[num_commands++] = Command(last_insert_len);
124
+ InitInsertCommand(&commands[num_commands++], last_insert_len);
118
125
  num_literals += last_insert_len;
119
126
  }
120
127
  assert(num_commands != 0);
121
128
 
122
- // Build the meta-block.
129
+ /* Build the meta-block. */
123
130
  MetaBlockSplit mb;
124
- uint32_t num_direct_distance_codes =
125
- params.mode == BrotliParams::MODE_FONT ? 12 : 0;
126
- uint32_t distance_postfix_bits =
127
- params.mode == BrotliParams::MODE_FONT ? 1 : 0;
128
- ContextType literal_context_mode = utf8_mode ? CONTEXT_UTF8 : CONTEXT_SIGNED;
131
+ InitMetaBlockSplit(&mb);
132
+ num_direct_distance_codes = params->mode == BROTLI_MODE_FONT ? 12 : 0;
133
+ distance_postfix_bits = params->mode == BROTLI_MODE_FONT ? 1 : 0;
134
+ literal_context_mode = use_utf8_mode ? CONTEXT_UTF8 : CONTEXT_SIGNED;
129
135
  RecomputeDistancePrefixes(commands, num_commands,
130
136
  num_direct_distance_codes,
131
137
  distance_postfix_bits);
132
- if (params.quality <= 9) {
133
- BuildMetaBlockGreedy(&input[0], input_pos, mask,
138
+ if (params->quality < MIN_QUALITY_FOR_HQ_BLOCK_SPLITTING) {
139
+ BrotliBuildMetaBlockGreedy(m, input, input_pos, mask,
140
+ commands, num_commands,
141
+ &mb);
142
+ if (BROTLI_IS_OOM(m)) goto oom;
143
+ } else {
144
+ BrotliBuildMetaBlock(m, input, input_pos, mask, params,
145
+ prev_byte, prev_byte2,
134
146
  commands, num_commands,
147
+ literal_context_mode,
135
148
  &mb);
136
- } else {
137
- BuildMetaBlock(&input[0], input_pos, mask,
138
- prev_byte, prev_byte2,
139
- commands, num_commands,
140
- literal_context_mode,
141
- &mb);
149
+ if (BROTLI_IS_OOM(m)) goto oom;
142
150
  }
143
151
 
144
- // Set up the temporary output storage.
145
- const size_t max_out_size = 2 * input_size + 500;
146
- std::vector<uint8_t> storage(max_out_size);
147
- uint8_t first_byte = 0;
148
- size_t first_byte_bits = 0;
152
+ /* Set up the temporary output storage. */
153
+ storage = BROTLI_ALLOC(m, uint8_t, 2 * input_size + 500);
154
+ if (BROTLI_IS_OOM(m)) goto oom;
155
+ first_byte = 0;
156
+ first_byte_bits = 0;
149
157
  if (is_first) {
150
- if (params.lgwin == 16) {
158
+ if (params->lgwin == 16) {
151
159
  first_byte = 0;
152
160
  first_byte_bits = 1;
153
- } else if (params.lgwin == 17) {
161
+ } else if (params->lgwin == 17) {
154
162
  first_byte = 1;
155
163
  first_byte_bits = 7;
156
164
  } else {
157
- first_byte = static_cast<uint8_t>(((params.lgwin - 17) << 1) | 1);
165
+ first_byte = static_cast<uint8_t>(((params->lgwin - 17) << 1) | 1);
158
166
  first_byte_bits = 4;
159
167
  }
160
168
  }
161
169
  storage[0] = static_cast<uint8_t>(first_byte);
162
- size_t storage_ix = first_byte_bits;
163
-
164
- // Store the meta-block to the temporary output.
165
- StoreMetaBlock(&input[0], input_pos, input_size, mask,
166
- prev_byte, prev_byte2,
167
- is_last,
168
- num_direct_distance_codes,
169
- distance_postfix_bits,
170
- literal_context_mode,
171
- commands, num_commands,
172
- mb,
173
- &storage_ix, &storage[0]);
174
- free(commands);
175
-
176
- // If this is not the last meta-block, store an empty metadata
177
- // meta-block so that the meta-block will end at a byte boundary.
170
+ storage_ix = first_byte_bits;
171
+
172
+ /* Store the meta-block to the temporary output. */
173
+ BrotliStoreMetaBlock(m, input, input_pos, input_size, mask,
174
+ prev_byte, prev_byte2,
175
+ TO_BROTLI_BOOL(is_last),
176
+ num_direct_distance_codes,
177
+ distance_postfix_bits,
178
+ literal_context_mode,
179
+ commands, num_commands,
180
+ &mb,
181
+ &storage_ix, storage);
182
+ if (BROTLI_IS_OOM(m)) goto oom;
183
+ DestroyMetaBlockSplit(m, &mb);
184
+ BROTLI_FREE(m, commands);
185
+
186
+ /* If this is not the last meta-block, store an empty metadata
187
+ meta-block so that the meta-block will end at a byte boundary. */
178
188
  if (!is_last) {
179
- StoreSyncMetaBlock(&storage_ix, &storage[0]);
189
+ BrotliStoreSyncMetaBlock(&storage_ix, storage);
180
190
  }
181
191
 
182
- // If the compressed data is too large, fall back to an uncompressed
183
- // meta-block.
184
- size_t output_size = storage_ix >> 3;
192
+ /* If the compressed data is too large, fall back to an uncompressed
193
+ meta-block. */
194
+ output_size = storage_ix >> 3;
185
195
  if (input_size + 4 < output_size) {
186
196
  storage[0] = static_cast<uint8_t>(first_byte);
187
197
  storage_ix = first_byte_bits;
188
- StoreUncompressedMetaBlock(is_last, &input[0], input_pos, mask,
189
- input_size,
190
- &storage_ix, &storage[0]);
198
+ BrotliStoreUncompressedMetaBlock(
199
+ TO_BROTLI_BOOL(is_last), input, input_pos, mask, input_size,
200
+ &storage_ix, storage);
191
201
  output_size = storage_ix >> 3;
192
202
  }
193
203
 
194
- // Copy the temporary output with size-check to the output.
204
+ /* Copy the temporary output with size-check to the output. */
195
205
  if (output_size > *encoded_size) {
196
- return false;
206
+ BROTLI_FREE(m, storage);
207
+ BROTLI_FREE(m, input);
208
+ return 0;
197
209
  }
198
- memcpy(encoded_buffer, &storage[0], output_size);
210
+ memcpy(encoded_buffer, storage, output_size);
199
211
  *encoded_size = output_size;
200
- return true;
212
+ BROTLI_FREE(m, storage);
213
+ BROTLI_FREE(m, input);
214
+ return 1;
215
+
216
+ oom:
217
+ BrotliWipeOutMemoryManager(m);
218
+ return 0;
201
219
  }
202
220
 
203
- } // namespace
221
+ } /* namespace */
204
222
 
205
- int BrotliCompressBufferParallel(BrotliParams params,
223
+ int BrotliCompressBufferParallel(BrotliParams compressor_params,
206
224
  size_t input_size,
207
225
  const uint8_t* input_buffer,
208
226
  size_t* encoded_size,
209
227
  uint8_t* encoded_buffer) {
210
228
  if (*encoded_size == 0) {
211
- // Output buffer needs at least one byte.
229
+ /* Output buffer needs at least one byte. */
212
230
  return 0;
213
- } else if (input_size == 0) {
231
+ } else if (input_size == 0) {
214
232
  encoded_buffer[0] = 6;
215
233
  *encoded_size = 1;
216
234
  return 1;
217
235
  }
218
236
 
219
- // Sanitize params.
220
- if (params.lgwin < kMinWindowBits) {
221
- params.lgwin = kMinWindowBits;
222
- } else if (params.lgwin > kMaxWindowBits) {
223
- params.lgwin = kMaxWindowBits;
224
- }
225
- if (params.lgblock == 0) {
226
- params.lgblock = 16;
227
- if (params.quality >= 9 && params.lgwin > params.lgblock) {
228
- params.lgblock = std::min(21, params.lgwin);
229
- }
230
- } else if (params.lgblock < kMinInputBlockBits) {
231
- params.lgblock = kMinInputBlockBits;
232
- } else if (params.lgblock > kMaxInputBlockBits) {
233
- params.lgblock = kMaxInputBlockBits;
234
- }
237
+ BrotliEncoderParams params;
238
+ params.mode = (BrotliEncoderMode)compressor_params.mode;
239
+ params.quality = compressor_params.quality;
240
+ params.lgwin = compressor_params.lgwin;
241
+ params.lgblock = compressor_params.lgblock;
242
+
243
+ SanitizeParams(&params);
244
+ params.lgblock = ComputeLgBlock(&params);
235
245
  size_t max_input_block_size = 1 << params.lgblock;
236
246
  size_t max_prefix_size = 1u << params.lgwin;
237
247
 
238
248
  std::vector<std::vector<uint8_t> > compressed_pieces;
239
249
 
240
- // Compress block-by-block independently.
250
+ /* Compress block-by-block independently. */
241
251
  for (size_t pos = 0; pos < input_size; ) {
242
- uint32_t input_block_size =
243
- static_cast<uint32_t>(std::min(max_input_block_size, input_size - pos));
252
+ uint32_t input_block_size = static_cast<uint32_t>(
253
+ BROTLI_MIN(size_t, max_input_block_size, input_size - pos));
244
254
  uint32_t prefix_size =
245
- static_cast<uint32_t>(std::min(max_prefix_size, pos));
255
+ static_cast<uint32_t>(BROTLI_MIN(size_t, max_prefix_size, pos));
246
256
  size_t out_size = input_block_size + (input_block_size >> 3) + 1024;
247
257
  std::vector<uint8_t> out(out_size);
248
- if (!WriteMetaBlockParallel(params,
258
+ if (!WriteMetaBlockParallel(&params,
249
259
  input_block_size,
250
260
  &input_buffer[pos],
251
261
  prefix_size,
252
262
  &input_buffer[pos - prefix_size],
253
- pos == 0,
254
- pos + input_block_size == input_size,
263
+ (pos == 0) ? 1 : 0,
264
+ (pos + input_block_size == input_size) ? 1 : 0,
255
265
  &out_size,
256
266
  &out[0])) {
257
- return false;
267
+ return 0;
258
268
  }
259
269
  out.resize(out_size);
260
270
  compressed_pieces.push_back(out);
261
271
  pos += input_block_size;
262
272
  }
263
273
 
264
- // Piece together the output.
274
+ /* Piece together the output. */
265
275
  size_t out_pos = 0;
266
276
  for (size_t i = 0; i < compressed_pieces.size(); ++i) {
267
277
  const std::vector<uint8_t>& out = compressed_pieces[i];
268
278
  if (out_pos + out.size() > *encoded_size) {
269
- return false;
279
+ return 0;
270
280
  }
271
281
  memcpy(&encoded_buffer[out_pos], &out[0], out.size());
272
282
  out_pos += out.size();
273
283
  }
274
284
  *encoded_size = out_pos;
275
285
 
276
- return true;
286
+ return 1;
277
287
  }
278
288
 
279
- } // namespace brotli
289
+ } /* namespace brotli */
@@ -4,16 +4,15 @@
4
4
  See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
5
  */
6
6
 
7
- // API for parallel Brotli compression
8
- // Note that this is only a proof of concept currently and not part of the
9
- // final API yet.
7
+ /* API for parallel Brotli compression
8
+ Note that this is only a proof of concept currently and not part of the
9
+ final API yet. */
10
10
 
11
11
  #ifndef BROTLI_ENC_ENCODE_PARALLEL_H_
12
12
  #define BROTLI_ENC_ENCODE_PARALLEL_H_
13
13
 
14
-
15
- #include "./encode.h"
16
- #include "./types.h"
14
+ #include "../common/types.h"
15
+ #include "./compressor.h"
17
16
 
18
17
  namespace brotli {
19
18
 
@@ -23,6 +22,6 @@ int BrotliCompressBufferParallel(BrotliParams params,
23
22
  size_t* encoded_size,
24
23
  uint8_t* encoded_buffer);
25
24
 
26
- } // namespace brotli
25
+ } /* namespace brotli */
27
26
 
28
- #endif // BROTLI_ENC_ENCODE_PARALLEL_H_
27
+ #endif /* BROTLI_ENC_ENCODE_PARALLEL_H_ */