brotli 0.1.8 → 0.2.0

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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +7 -3
  4. data/brotli.gemspec +1 -1
  5. data/ext/brotli/brotli.c +4 -4
  6. data/ext/brotli/brotli.h +2 -2
  7. data/ext/brotli/extconf.rb +9 -16
  8. data/lib/brotli/version.rb +1 -1
  9. data/vendor/brotli/{common → c/common}/constants.h +11 -1
  10. data/vendor/brotli/c/common/dictionary.bin +432 -0
  11. data/vendor/brotli/c/common/dictionary.c +5905 -0
  12. data/vendor/brotli/c/common/dictionary.h +64 -0
  13. data/vendor/brotli/c/common/version.h +19 -0
  14. data/vendor/brotli/{dec → c/dec}/bit_reader.c +2 -2
  15. data/vendor/brotli/{dec → c/dec}/bit_reader.h +11 -34
  16. data/vendor/brotli/{dec → c/dec}/context.h +1 -1
  17. data/vendor/brotli/{dec → c/dec}/decode.c +389 -356
  18. data/vendor/brotli/{dec → c/dec}/huffman.c +24 -23
  19. data/vendor/brotli/{dec → c/dec}/huffman.h +1 -1
  20. data/vendor/brotli/{dec → c/dec}/port.h +19 -10
  21. data/vendor/brotli/{dec → c/dec}/prefix.h +1 -1
  22. data/vendor/brotli/{dec → c/dec}/state.c +23 -19
  23. data/vendor/brotli/{dec → c/dec}/state.h +18 -17
  24. data/vendor/brotli/{dec → c/dec}/transform.h +2 -2
  25. data/vendor/brotli/c/enc/backward_references.c +134 -0
  26. data/vendor/brotli/c/enc/backward_references.h +39 -0
  27. data/vendor/brotli/{enc/backward_references.c → c/enc/backward_references_hq.c} +144 -232
  28. data/vendor/brotli/{enc/backward_references.h → c/enc/backward_references_hq.h} +28 -31
  29. data/vendor/brotli/{enc → c/enc}/backward_references_inc.h +37 -31
  30. data/vendor/brotli/{enc → c/enc}/bit_cost.c +1 -1
  31. data/vendor/brotli/{enc → c/enc}/bit_cost.h +1 -1
  32. data/vendor/brotli/{enc → c/enc}/bit_cost_inc.h +0 -0
  33. data/vendor/brotli/{enc → c/enc}/block_encoder_inc.h +0 -0
  34. data/vendor/brotli/{enc → c/enc}/block_splitter.c +2 -4
  35. data/vendor/brotli/{enc → c/enc}/block_splitter.h +1 -1
  36. data/vendor/brotli/{enc → c/enc}/block_splitter_inc.h +6 -7
  37. data/vendor/brotli/{enc → c/enc}/brotli_bit_stream.c +22 -26
  38. data/vendor/brotli/{enc → c/enc}/brotli_bit_stream.h +1 -5
  39. data/vendor/brotli/{enc → c/enc}/cluster.c +1 -1
  40. data/vendor/brotli/{enc → c/enc}/cluster.h +1 -1
  41. data/vendor/brotli/{enc → c/enc}/cluster_inc.h +2 -0
  42. data/vendor/brotli/{enc → c/enc}/command.h +34 -17
  43. data/vendor/brotli/{enc → c/enc}/compress_fragment.c +97 -53
  44. data/vendor/brotli/{enc → c/enc}/compress_fragment.h +5 -2
  45. data/vendor/brotli/{enc → c/enc}/compress_fragment_two_pass.c +106 -51
  46. data/vendor/brotli/{enc → c/enc}/compress_fragment_two_pass.h +5 -2
  47. data/vendor/brotli/{enc → c/enc}/context.h +3 -3
  48. data/vendor/brotli/c/enc/dictionary_hash.c +1120 -0
  49. data/vendor/brotli/c/enc/dictionary_hash.h +24 -0
  50. data/vendor/brotli/{enc → c/enc}/encode.c +442 -240
  51. data/vendor/brotli/{enc → c/enc}/entropy_encode.c +9 -9
  52. data/vendor/brotli/{enc → c/enc}/entropy_encode.h +4 -4
  53. data/vendor/brotli/{enc → c/enc}/entropy_encode_static.h +4 -4
  54. data/vendor/brotli/{enc → c/enc}/fast_log.h +3 -3
  55. data/vendor/brotli/{enc → c/enc}/find_match_length.h +8 -8
  56. data/vendor/brotli/c/enc/hash.h +446 -0
  57. data/vendor/brotli/{enc → c/enc}/hash_forgetful_chain_inc.h +72 -68
  58. data/vendor/brotli/c/enc/hash_longest_match64_inc.h +266 -0
  59. data/vendor/brotli/c/enc/hash_longest_match_inc.h +258 -0
  60. data/vendor/brotli/{enc → c/enc}/hash_longest_match_quickly_inc.h +81 -77
  61. data/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +326 -0
  62. data/vendor/brotli/{enc → c/enc}/histogram.c +4 -2
  63. data/vendor/brotli/{enc → c/enc}/histogram.h +1 -1
  64. data/vendor/brotli/{enc → c/enc}/histogram_inc.h +0 -0
  65. data/vendor/brotli/{enc → c/enc}/literal_cost.c +4 -7
  66. data/vendor/brotli/{enc → c/enc}/literal_cost.h +2 -2
  67. data/vendor/brotli/{enc → c/enc}/memory.c +1 -1
  68. data/vendor/brotli/{enc → c/enc}/memory.h +3 -2
  69. data/vendor/brotli/{enc → c/enc}/metablock.c +136 -123
  70. data/vendor/brotli/{enc → c/enc}/metablock.h +2 -12
  71. data/vendor/brotli/{enc → c/enc}/metablock_inc.h +0 -0
  72. data/vendor/brotli/{enc → c/enc}/port.h +49 -33
  73. data/vendor/brotli/{enc → c/enc}/prefix.h +4 -2
  74. data/vendor/brotli/{enc → c/enc}/quality.h +47 -17
  75. data/vendor/brotli/{enc → c/enc}/ringbuffer.h +6 -6
  76. data/vendor/brotli/{enc → c/enc}/static_dict.c +26 -22
  77. data/vendor/brotli/{enc → c/enc}/static_dict.h +3 -1
  78. data/vendor/brotli/c/enc/static_dict_lut.h +5864 -0
  79. data/vendor/brotli/{enc → c/enc}/utf8_util.c +1 -1
  80. data/vendor/brotli/{enc → c/enc}/utf8_util.h +2 -2
  81. data/vendor/brotli/{enc → c/enc}/write_bits.h +3 -3
  82. data/vendor/brotli/c/include/brotli/decode.h +339 -0
  83. data/vendor/brotli/c/include/brotli/encode.h +402 -0
  84. data/vendor/brotli/c/include/brotli/port.h +146 -0
  85. data/vendor/brotli/c/include/brotli/types.h +90 -0
  86. metadata +80 -79
  87. data/vendor/brotli/common/dictionary.c +0 -9474
  88. data/vendor/brotli/common/dictionary.h +0 -29
  89. data/vendor/brotli/common/port.h +0 -107
  90. data/vendor/brotli/common/types.h +0 -58
  91. data/vendor/brotli/dec/decode.h +0 -188
  92. data/vendor/brotli/enc/compressor.cc +0 -139
  93. data/vendor/brotli/enc/compressor.h +0 -161
  94. data/vendor/brotli/enc/dictionary_hash.h +0 -4121
  95. data/vendor/brotli/enc/encode.h +0 -221
  96. data/vendor/brotli/enc/encode_parallel.cc +0 -289
  97. data/vendor/brotli/enc/encode_parallel.h +0 -27
  98. data/vendor/brotli/enc/hash.h +0 -717
  99. data/vendor/brotli/enc/hash_longest_match_inc.h +0 -241
  100. data/vendor/brotli/enc/static_dict_lut.h +0 -11241
  101. data/vendor/brotli/enc/streams.cc +0 -114
  102. data/vendor/brotli/enc/streams.h +0 -121
@@ -11,7 +11,7 @@
11
11
  #include <string.h> /* memcpy, memset */
12
12
 
13
13
  #include "../common/constants.h"
14
- #include "../common/types.h"
14
+ #include <brotli/types.h>
15
15
  #include "./port.h"
16
16
 
17
17
  #if defined(__cplusplus) || defined(c_plusplus)
@@ -21,7 +21,8 @@ extern "C" {
21
21
  #define BROTLI_REVERSE_BITS_MAX 8
22
22
 
23
23
  #ifdef BROTLI_RBIT
24
- #define BROTLI_REVERSE_BITS_BASE (32 - BROTLI_REVERSE_BITS_MAX)
24
+ #define BROTLI_REVERSE_BITS_BASE \
25
+ ((sizeof(reg_t) << 3) - BROTLI_REVERSE_BITS_MAX)
25
26
  #else
26
27
  #define BROTLI_REVERSE_BITS_BASE 0
27
28
  static uint8_t kReverseBits[1 << BROTLI_REVERSE_BITS_MAX] = {
@@ -61,12 +62,12 @@ static uint8_t kReverseBits[1 << BROTLI_REVERSE_BITS_MAX] = {
61
62
  #endif /* BROTLI_RBIT */
62
63
 
63
64
  #define BROTLI_REVERSE_BITS_LOWEST \
64
- (1U << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
65
+ ((reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
65
66
 
66
67
  /* Returns reverse(num >> BROTLI_REVERSE_BITS_BASE, BROTLI_REVERSE_BITS_MAX),
67
68
  where reverse(value, len) is the bit-wise reversal of the len least
68
69
  significant bits of value. */
69
- static BROTLI_INLINE uint32_t BrotliReverseBits(uint32_t num) {
70
+ static BROTLI_INLINE reg_t BrotliReverseBits(reg_t num) {
70
71
  #ifdef BROTLI_RBIT
71
72
  return BROTLI_RBIT(num);
72
73
  #else
@@ -103,12 +104,12 @@ static BROTLI_INLINE int NextTableBitSize(const uint16_t* const count,
103
104
  void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* table,
104
105
  const uint8_t* const code_lengths,
105
106
  uint16_t* count) {
106
- HuffmanCode code; /* current table entry */
107
- int symbol; /* symbol index in original or sorted table */
108
- uint32_t key; /* prefix code */
109
- uint32_t key_step; /* prefix code addend */
110
- int step; /* step size to replicate values in current table */
111
- int table_size; /* size of current table */
107
+ HuffmanCode code; /* current table entry */
108
+ int symbol; /* symbol index in original or sorted table */
109
+ reg_t key; /* prefix code */
110
+ reg_t key_step; /* prefix code addend */
111
+ int step; /* step size to replicate values in current table */
112
+ int table_size; /* size of current table */
112
113
  int sorted[BROTLI_CODE_LENGTH_CODES]; /* symbols sorted by code length */
113
114
  /* offsets in sorted table for each length */
114
115
  int offset[BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH + 1];
@@ -143,7 +144,7 @@ void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* table,
143
144
  if (offset[0] == 0) {
144
145
  code.bits = 0;
145
146
  code.value = (uint16_t)sorted[0];
146
- for (key = 0; key < (uint32_t)table_size; ++key) {
147
+ for (key = 0; key < (reg_t)table_size; ++key) {
147
148
  table[key] = code;
148
149
  }
149
150
  return;
@@ -171,18 +172,18 @@ uint32_t BrotliBuildHuffmanTable(HuffmanCode* root_table,
171
172
  int root_bits,
172
173
  const uint16_t* const symbol_lists,
173
174
  uint16_t* count) {
174
- HuffmanCode code; /* current table entry */
175
- HuffmanCode* table; /* next available space in table */
176
- int len; /* current code length */
177
- int symbol; /* symbol index in original or sorted table */
178
- uint32_t key; /* prefix code */
179
- uint32_t key_step; /* prefix code addend */
180
- uint32_t sub_key; /* 2nd level table prefix code */
181
- uint32_t sub_key_step; /* 2nd level table prefix code addend */
182
- int step; /* step size to replicate values in current table */
183
- int table_bits; /* key length of current table */
184
- int table_size; /* size of current table */
185
- int total_size; /* sum of root table size and 2nd level table sizes */
175
+ HuffmanCode code; /* current table entry */
176
+ HuffmanCode* table; /* next available space in table */
177
+ int len; /* current code length */
178
+ int symbol; /* symbol index in original or sorted table */
179
+ reg_t key; /* prefix code */
180
+ reg_t key_step; /* prefix code addend */
181
+ reg_t sub_key; /* 2nd level table prefix code */
182
+ reg_t sub_key_step; /* 2nd level table prefix code addend */
183
+ int step; /* step size to replicate values in current table */
184
+ int table_bits; /* key length of current table */
185
+ int table_size; /* size of current table */
186
+ int total_size; /* sum of root table size and 2nd level table sizes */
186
187
  int max_length = -1;
187
188
  int bits;
188
189
  int bits_count;
@@ -9,7 +9,7 @@
9
9
  #ifndef BROTLI_DEC_HUFFMAN_H_
10
10
  #define BROTLI_DEC_HUFFMAN_H_
11
11
 
12
- #include "../common/types.h"
12
+ #include <brotli/types.h>
13
13
  #include "./port.h"
14
14
 
15
15
  #if defined(__cplusplus) || defined(c_plusplus)
@@ -16,6 +16,7 @@
16
16
  features and attributes
17
17
  * BROTLI_BUILD_PORTABLE disables dangerous optimizations, like unaligned
18
18
  read and overlapping memcpy; this reduces decompression speed by 5%
19
+ * BROTLI_BUILD_NO_RBIT disables "rbit" optimization for ARM CPUs
19
20
  * BROTLI_DEBUG dumps file name and line number when decoder detects stream
20
21
  or memory error
21
22
  * BROTLI_ENABLE_LOG enables asserts and dumps various state information
@@ -29,16 +30,16 @@
29
30
  #include <stdio.h>
30
31
  #endif
31
32
 
32
- #include "../common/port.h"
33
+ #include <brotli/port.h>
33
34
 
34
35
  #if defined(__arm__) || defined(__thumb__) || \
35
- defined(_M_ARM) || defined(_M_ARMT)
36
+ defined(_M_ARM) || defined(_M_ARMT) || defined(__ARM64_ARCH_8__)
36
37
  #define BROTLI_TARGET_ARM
37
- #if (defined(__ARM_ARCH) && (__ARM_ARCH >= 7)) || \
38
- (defined(M_ARM) && (M_ARM >= 7))
38
+ #if (defined(__ARM_ARCH) && (__ARM_ARCH == 7)) || \
39
+ (defined(M_ARM) && (M_ARM == 7))
39
40
  #define BROTLI_TARGET_ARMV7
40
41
  #endif /* ARMv7 */
41
- #if defined(__aarch64__)
42
+ #if defined(__aarch64__) || defined(__ARM64_ARCH_8__)
42
43
  #define BROTLI_TARGET_ARMV8
43
44
  #endif /* ARMv8 */
44
45
  #endif /* ARM */
@@ -59,7 +60,7 @@
59
60
  #define BROTLI_ALIGNED_READ (!!1)
60
61
  #elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \
61
62
  defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
62
- /* Allow unaligned read only for whitelisted CPUs. */
63
+ /* Allow unaligned read only for white-listed CPUs. */
63
64
  #define BROTLI_ALIGNED_READ (!!0)
64
65
  #else
65
66
  #define BROTLI_ALIGNED_READ (!!1)
@@ -101,6 +102,12 @@ static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) {
101
102
  #define BROTLI_64_BITS 0
102
103
  #endif
103
104
 
105
+ #if (BROTLI_64_BITS)
106
+ #define reg_t uint64_t
107
+ #else
108
+ #define reg_t uint32_t
109
+ #endif
110
+
104
111
  #if defined(BROTLI_BUILD_BIG_ENDIAN)
105
112
  #define BROTLI_LITTLE_ENDIAN 0
106
113
  #define BROTLI_BIG_ENDIAN 1
@@ -132,10 +139,12 @@ static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) {
132
139
  if ((N & 4) != 0) {X; X; X; X;} \
133
140
  }
134
141
 
135
- #if BROTLI_MODERN_COMPILER || defined(__llvm__)
136
- #if defined(BROTLI_TARGET_ARMV7)
137
- static BROTLI_INLINE unsigned BrotliRBit(unsigned input) {
138
- unsigned output;
142
+ #if (BROTLI_MODERN_COMPILER || defined(__llvm__)) && \
143
+ !defined(BROTLI_BUILD_NO_RBIT)
144
+ #if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
145
+ /* TODO: detect ARMv6T2 and enable this code for it. */
146
+ static BROTLI_INLINE reg_t BrotliRBit(reg_t input) {
147
+ reg_t output;
139
148
  __asm__("rbit %0, %1\n" : "=r"(output) : "r"(input));
140
149
  return output;
141
150
  }
@@ -12,7 +12,7 @@
12
12
  #define BROTLI_DEC_PREFIX_H_
13
13
 
14
14
  #include "../common/constants.h"
15
- #include "../common/types.h"
15
+ #include <brotli/types.h>
16
16
 
17
17
  /* Represents the range of values belonging to a prefix code: */
18
18
  /* [offset, offset + 2^nbits) */
@@ -8,7 +8,7 @@
8
8
 
9
9
  #include <stdlib.h> /* free, malloc */
10
10
 
11
- #include "../common/types.h"
11
+ #include <brotli/types.h>
12
12
  #include "./huffman.h"
13
13
 
14
14
  #if defined(__cplusplus) || defined(c_plusplus)
@@ -41,6 +41,8 @@ void BrotliDecoderStateInitWithCustomAllocators(BrotliDecoderState* s,
41
41
  s->memory_manager_opaque = opaque;
42
42
  }
43
43
 
44
+ s->error_code = 0; /* BROTLI_DECODER_NO_ERROR */
45
+
44
46
  BrotliInitBitReader(&s->br);
45
47
  s->state = BROTLI_STATE_UNINITED;
46
48
  s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE;
@@ -51,6 +53,8 @@ void BrotliDecoderStateInitWithCustomAllocators(BrotliDecoderState* s,
51
53
  s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE;
52
54
  s->substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_NONE;
53
55
 
56
+ s->dictionary = BrotliGetDictionary();
57
+
54
58
  s->buffer_length = 0;
55
59
  s->loop_counter = 0;
56
60
  s->pos = 0;
@@ -60,6 +64,9 @@ void BrotliDecoderStateInitWithCustomAllocators(BrotliDecoderState* s,
60
64
  s->block_type_trees = NULL;
61
65
  s->block_len_trees = NULL;
62
66
  s->ringbuffer = NULL;
67
+ s->ringbuffer_size = 0;
68
+ s->new_ringbuffer_size = 0;
69
+ s->ringbuffer_mask = 0;
63
70
 
64
71
  s->context_map = NULL;
65
72
  s->context_modes = NULL;
@@ -76,10 +83,12 @@ void BrotliDecoderStateInitWithCustomAllocators(BrotliDecoderState* s,
76
83
  s->distance_hgroup.codes = NULL;
77
84
  s->distance_hgroup.htrees = NULL;
78
85
 
79
- s->custom_dict = NULL;
80
- s->custom_dict_size = 0;
81
-
82
86
  s->is_last_metablock = 0;
87
+ s->is_uncompressed = 0;
88
+ s->is_metadata = 0;
89
+ s->should_wrap_ringbuffer = 0;
90
+ s->canny_ringbuffer_allocation = 1;
91
+
83
92
  s->window_bits = 0;
84
93
  s->max_distance = 0;
85
94
  s->dist_rb[0] = 16;
@@ -93,7 +102,7 @@ void BrotliDecoderStateInitWithCustomAllocators(BrotliDecoderState* s,
93
102
  /* Make small negative indexes addressable. */
94
103
  s->symbol_lists = &s->symbols_lists_array[BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1];
95
104
 
96
- s->mtf_upper_bound = 255;
105
+ s->mtf_upper_bound = 63;
97
106
  }
98
107
 
99
108
  void BrotliDecoderStateMetablockBegin(BrotliDecoderState* s) {
@@ -131,10 +140,9 @@ void BrotliDecoderStateCleanupAfterMetablock(BrotliDecoderState* s) {
131
140
  BROTLI_FREE(s, s->context_modes);
132
141
  BROTLI_FREE(s, s->context_map);
133
142
  BROTLI_FREE(s, s->dist_context_map);
134
-
135
- BrotliDecoderHuffmanTreeGroupRelease(s, &s->literal_hgroup);
136
- BrotliDecoderHuffmanTreeGroupRelease(s, &s->insert_copy_hgroup);
137
- BrotliDecoderHuffmanTreeGroupRelease(s, &s->distance_hgroup);
143
+ BROTLI_FREE(s, s->literal_hgroup.htrees);
144
+ BROTLI_FREE(s, s->insert_copy_hgroup.htrees);
145
+ BROTLI_FREE(s, s->distance_hgroup.htrees);
138
146
  }
139
147
 
140
148
  void BrotliDecoderStateCleanup(BrotliDecoderState* s) {
@@ -144,23 +152,19 @@ void BrotliDecoderStateCleanup(BrotliDecoderState* s) {
144
152
  BROTLI_FREE(s, s->block_type_trees);
145
153
  }
146
154
 
147
- void BrotliDecoderHuffmanTreeGroupInit(BrotliDecoderState* s,
155
+ BROTLI_BOOL BrotliDecoderHuffmanTreeGroupInit(BrotliDecoderState* s,
148
156
  HuffmanTreeGroup* group, uint32_t alphabet_size, uint32_t ntrees) {
149
157
  /* Pack two allocations into one */
150
158
  const size_t max_table_size = kMaxHuffmanTableSize[(alphabet_size + 31) >> 5];
151
159
  const size_t code_size = sizeof(HuffmanCode) * ntrees * max_table_size;
152
160
  const size_t htree_size = sizeof(HuffmanCode*) * ntrees;
153
- char* p = (char*)BROTLI_ALLOC(s, code_size + htree_size);
161
+ /* Pointer alignment is, hopefully, wider than sizeof(HuffmanCode). */
162
+ HuffmanCode** p = (HuffmanCode**)BROTLI_ALLOC(s, code_size + htree_size);
154
163
  group->alphabet_size = (uint16_t)alphabet_size;
155
164
  group->num_htrees = (uint16_t)ntrees;
156
- group->codes = (HuffmanCode*)p;
157
- group->htrees = (HuffmanCode**)(p + code_size);
158
- }
159
-
160
- void BrotliDecoderHuffmanTreeGroupRelease(
161
- BrotliDecoderState* s, HuffmanTreeGroup* group) {
162
- BROTLI_FREE(s, group->codes);
163
- group->htrees = NULL;
165
+ group->htrees = p;
166
+ group->codes = (HuffmanCode*)(&p[ntrees]);
167
+ return !!p;
164
168
  }
165
169
 
166
170
  #if defined(__cplusplus) || defined(c_plusplus)
@@ -10,7 +10,8 @@
10
10
  #define BROTLI_DEC_STATE_H_
11
11
 
12
12
  #include "../common/constants.h"
13
- #include "../common/types.h"
13
+ #include "../common/dictionary.h"
14
+ #include <brotli/types.h>
14
15
  #include "./bit_reader.h"
15
16
  #include "./huffman.h"
16
17
  #include "./port.h"
@@ -115,7 +116,6 @@ struct BrotliDecoderStateStruct {
115
116
 
116
117
  int pos;
117
118
  int max_backward_distance;
118
- int max_backward_distance_minus_custom_dict_size;
119
119
  int max_distance;
120
120
  int ringbuffer_size;
121
121
  int ringbuffer_mask;
@@ -141,6 +141,8 @@ struct BrotliDecoderStateStruct {
141
141
  /* This is true if the literal context map histogram type always matches the
142
142
  block type. It is then not needed to keep the context (faster decoding). */
143
143
  int trivial_literal_context;
144
+ /* Distance context is actual after command is decoded and before distance
145
+ is computed. After distance computation it is used as a temporary variable. */
144
146
  int distance_context;
145
147
  int meta_block_remaining_len;
146
148
  uint32_t block_length_index;
@@ -161,8 +163,8 @@ struct BrotliDecoderStateStruct {
161
163
  int distance_code;
162
164
 
163
165
  /* For partial write operations */
164
- size_t rb_roundtrips; /* How many times we went around the ringbuffer */
165
- size_t partial_pos_out; /* How much output to the user in total (<= rb) */
166
+ size_t rb_roundtrips; /* How many times we went around the ring-buffer */
167
+ size_t partial_pos_out; /* How much output to the user in total */
166
168
 
167
169
  /* For ReadHuffmanCode */
168
170
  uint32_t symbol;
@@ -170,7 +172,7 @@ struct BrotliDecoderStateStruct {
170
172
  uint32_t space;
171
173
 
172
174
  HuffmanCode table[32];
173
- /* List of of symbol chains. */
175
+ /* List of heads of symbol chains. */
174
176
  uint16_t* symbol_lists;
175
177
  /* Storage from symbol_lists. */
176
178
  uint16_t symbols_lists_array[BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1 +
@@ -193,11 +195,7 @@ struct BrotliDecoderStateStruct {
193
195
 
194
196
  /* For InverseMoveToFrontTransform */
195
197
  uint32_t mtf_upper_bound;
196
- uint8_t mtf[256 + 4];
197
-
198
- /* For custom dictionaries */
199
- const uint8_t* custom_dict;
200
- int custom_dict_size;
198
+ uint32_t mtf[64 + 1];
201
199
 
202
200
  /* less used attributes are in the end of this struct */
203
201
  /* States inside function calls */
@@ -209,15 +207,20 @@ struct BrotliDecoderStateStruct {
209
207
  BrotliRunningDecodeUint8State substate_decode_uint8;
210
208
  BrotliRunningReadBlockLengthState substate_read_block_length;
211
209
 
212
- uint8_t is_last_metablock;
213
- uint8_t is_uncompressed;
214
- uint8_t is_metadata;
215
- uint8_t size_nibbles;
210
+ unsigned int is_last_metablock : 1;
211
+ unsigned int is_uncompressed : 1;
212
+ unsigned int is_metadata : 1;
213
+ unsigned int should_wrap_ringbuffer : 1;
214
+ unsigned int canny_ringbuffer_allocation : 1;
215
+ unsigned int size_nibbles : 8;
216
216
  uint32_t window_bits;
217
217
 
218
+ int new_ringbuffer_size;
219
+
218
220
  uint32_t num_literal_htrees;
219
221
  uint8_t* context_map;
220
222
  uint8_t* context_modes;
223
+ const BrotliDictionary* dictionary;
221
224
 
222
225
  uint32_t trivial_literal_contexts[8]; /* 256 bits */
223
226
  };
@@ -233,11 +236,9 @@ BROTLI_INTERNAL void BrotliDecoderStateCleanup(BrotliDecoderState* s);
233
236
  BROTLI_INTERNAL void BrotliDecoderStateMetablockBegin(BrotliDecoderState* s);
234
237
  BROTLI_INTERNAL void BrotliDecoderStateCleanupAfterMetablock(
235
238
  BrotliDecoderState* s);
236
- BROTLI_INTERNAL void BrotliDecoderHuffmanTreeGroupInit(
239
+ BROTLI_INTERNAL BROTLI_BOOL BrotliDecoderHuffmanTreeGroupInit(
237
240
  BrotliDecoderState* s, HuffmanTreeGroup* group, uint32_t alphabet_size,
238
241
  uint32_t ntrees);
239
- BROTLI_INTERNAL void BrotliDecoderHuffmanTreeGroupRelease(
240
- BrotliDecoderState* s, HuffmanTreeGroup* group);
241
242
 
242
243
  #if defined(__cplusplus) || defined(c_plusplus)
243
244
  } /* extern "C" */
@@ -9,7 +9,7 @@
9
9
  #ifndef BROTLI_DEC_TRANSFORM_H_
10
10
  #define BROTLI_DEC_TRANSFORM_H_
11
11
 
12
- #include "../common/types.h"
12
+ #include <brotli/types.h>
13
13
  #include "./port.h"
14
14
 
15
15
  #if defined(__cplusplus) || defined(c_plusplus)
@@ -247,7 +247,7 @@ static int ToUpperCase(uint8_t* p) {
247
247
  }
248
248
  return 1;
249
249
  }
250
- /* An overly simplified uppercasing model for utf-8. */
250
+ /* An overly simplified uppercasing model for UTF-8. */
251
251
  if (p[0] < 0xe0) {
252
252
  p[1] ^= 32;
253
253
  return 2;
@@ -0,0 +1,134 @@
1
+ /* Copyright 2013 Google Inc. All Rights Reserved.
2
+
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
+ */
6
+
7
+ /* Function to find backward reference copies. */
8
+
9
+ #include "./backward_references.h"
10
+
11
+ #include "../common/constants.h"
12
+ #include "../common/dictionary.h"
13
+ #include <brotli/types.h>
14
+ #include "./command.h"
15
+ #include "./dictionary_hash.h"
16
+ #include "./memory.h"
17
+ #include "./port.h"
18
+ #include "./quality.h"
19
+
20
+ #if defined(__cplusplus) || defined(c_plusplus)
21
+ extern "C" {
22
+ #endif
23
+
24
+ static BROTLI_INLINE size_t ComputeDistanceCode(size_t distance,
25
+ size_t max_distance,
26
+ const int* dist_cache) {
27
+ if (distance <= max_distance) {
28
+ size_t distance_plus_3 = distance + 3;
29
+ size_t offset0 = distance_plus_3 - (size_t)dist_cache[0];
30
+ size_t offset1 = distance_plus_3 - (size_t)dist_cache[1];
31
+ if (distance == (size_t)dist_cache[0]) {
32
+ return 0;
33
+ } else if (distance == (size_t)dist_cache[1]) {
34
+ return 1;
35
+ } else if (offset0 < 7) {
36
+ return (0x9750468 >> (4 * offset0)) & 0xF;
37
+ } else if (offset1 < 7) {
38
+ return (0xFDB1ACE >> (4 * offset1)) & 0xF;
39
+ } else if (distance == (size_t)dist_cache[2]) {
40
+ return 2;
41
+ } else if (distance == (size_t)dist_cache[3]) {
42
+ return 3;
43
+ }
44
+ }
45
+ return distance + BROTLI_NUM_DISTANCE_SHORT_CODES - 1;
46
+ }
47
+
48
+ #define EXPAND_CAT(a, b) CAT(a, b)
49
+ #define CAT(a, b) a ## b
50
+ #define FN(X) EXPAND_CAT(X, HASHER())
51
+ #define EXPORT_FN(X) EXPAND_CAT(X, EXPAND_CAT(PREFIX(), HASHER()))
52
+ #define PREFIX() N
53
+
54
+ #define HASHER() H2
55
+ /* NOLINTNEXTLINE(build/include) */
56
+ #include "./backward_references_inc.h"
57
+ #undef HASHER
58
+
59
+ #define HASHER() H3
60
+ /* NOLINTNEXTLINE(build/include) */
61
+ #include "./backward_references_inc.h"
62
+ #undef HASHER
63
+
64
+ #define HASHER() H4
65
+ /* NOLINTNEXTLINE(build/include) */
66
+ #include "./backward_references_inc.h"
67
+ #undef HASHER
68
+
69
+ #define HASHER() H5
70
+ /* NOLINTNEXTLINE(build/include) */
71
+ #include "./backward_references_inc.h"
72
+ #undef HASHER
73
+
74
+ #define HASHER() H6
75
+ /* NOLINTNEXTLINE(build/include) */
76
+ #include "./backward_references_inc.h"
77
+ #undef HASHER
78
+
79
+ #define HASHER() H40
80
+ /* NOLINTNEXTLINE(build/include) */
81
+ #include "./backward_references_inc.h"
82
+ #undef HASHER
83
+
84
+ #define HASHER() H41
85
+ /* NOLINTNEXTLINE(build/include) */
86
+ #include "./backward_references_inc.h"
87
+ #undef HASHER
88
+
89
+ #define HASHER() H42
90
+ /* NOLINTNEXTLINE(build/include) */
91
+ #include "./backward_references_inc.h"
92
+ #undef HASHER
93
+
94
+ #define HASHER() H54
95
+ /* NOLINTNEXTLINE(build/include) */
96
+ #include "./backward_references_inc.h"
97
+ #undef HASHER
98
+
99
+ #undef PREFIX
100
+ #undef EXPORT_FN
101
+ #undef FN
102
+ #undef CAT
103
+ #undef EXPAND_CAT
104
+
105
+ void BrotliCreateBackwardReferences(const BrotliDictionary* dictionary,
106
+ size_t num_bytes,
107
+ size_t position,
108
+ const uint8_t* ringbuffer,
109
+ size_t ringbuffer_mask,
110
+ const BrotliEncoderParams* params,
111
+ HasherHandle hasher,
112
+ int* dist_cache,
113
+ size_t* last_insert_len,
114
+ Command* commands,
115
+ size_t* num_commands,
116
+ size_t* num_literals) {
117
+ switch (params->hasher.type) {
118
+ #define CASE_(N) \
119
+ case N: \
120
+ CreateBackwardReferencesNH ## N(dictionary, \
121
+ kStaticDictionaryHash, num_bytes, position, ringbuffer, \
122
+ ringbuffer_mask, params, hasher, dist_cache, \
123
+ last_insert_len, commands, num_commands, num_literals); \
124
+ return;
125
+ FOR_GENERIC_HASHERS(CASE_)
126
+ #undef CASE_
127
+ default:
128
+ break;
129
+ }
130
+ }
131
+
132
+ #if defined(__cplusplus) || defined(c_plusplus)
133
+ } /* extern "C" */
134
+ #endif