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
@@ -9,28 +9,28 @@
9
9
  #ifndef BROTLI_DEC_DECODE_H_
10
10
  #define BROTLI_DEC_DECODE_H_
11
11
 
12
- #include "./types.h"
12
+ #include "../common/types.h"
13
13
 
14
14
  #if defined(__cplusplus) || defined(c_plusplus)
15
15
  extern "C" {
16
16
  #endif
17
17
 
18
- typedef struct BrotliStateStruct BrotliState;
18
+ typedef struct BrotliDecoderStateStruct BrotliDecoderState;
19
19
 
20
20
  typedef enum {
21
21
  /* Decoding error, e.g. corrupt input or memory allocation problem */
22
- BROTLI_RESULT_ERROR = 0,
22
+ BROTLI_DECODER_RESULT_ERROR = 0,
23
23
  /* Decoding successfully completed */
24
- BROTLI_RESULT_SUCCESS = 1,
24
+ BROTLI_DECODER_RESULT_SUCCESS = 1,
25
25
  /* Partially done; should be called again with more input */
26
- BROTLI_RESULT_NEEDS_MORE_INPUT = 2,
26
+ BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT = 2,
27
27
  /* Partially done; should be called again with more output */
28
- BROTLI_RESULT_NEEDS_MORE_OUTPUT = 3
29
- } BrotliResult;
28
+ BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT = 3
29
+ } BrotliDecoderResult;
30
30
 
31
- #define BROTLI_ERROR_CODES_LIST(BROTLI_ERROR_CODE, SEPARATOR) \
31
+ #define BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE, SEPARATOR) \
32
32
  BROTLI_ERROR_CODE(_, NO_ERROR, 0) SEPARATOR \
33
- /* Same as BrotliResult values */ \
33
+ /* Same as BrotliDecoderResult values */ \
34
34
  BROTLI_ERROR_CODE(_, SUCCESS, 1) SEPARATOR \
35
35
  BROTLI_ERROR_CODE(_, NEEDS_MORE_INPUT, 2) SEPARATOR \
36
36
  BROTLI_ERROR_CODE(_, NEEDS_MORE_OUTPUT, 3) SEPARATOR \
@@ -71,39 +71,29 @@ typedef enum {
71
71
  typedef enum {
72
72
  #define _BROTLI_COMMA ,
73
73
  #define _BROTLI_ERROR_CODE_ENUM_ITEM(PREFIX, NAME, CODE) \
74
- BROTLI ## PREFIX ## NAME = CODE
75
- BROTLI_ERROR_CODES_LIST(_BROTLI_ERROR_CODE_ENUM_ITEM, _BROTLI_COMMA)
74
+ BROTLI_DECODER ## PREFIX ## NAME = CODE
75
+ BROTLI_DECODER_ERROR_CODES_LIST(_BROTLI_ERROR_CODE_ENUM_ITEM, _BROTLI_COMMA)
76
76
  #undef _BROTLI_ERROR_CODE_ENUM_ITEM
77
77
  #undef _BROTLI_COMMA
78
- } BrotliErrorCode;
78
+ } BrotliDecoderErrorCode;
79
79
 
80
- #define BROTLI_LAST_ERROR_CODE BROTLI_ERROR_UNREACHABLE
80
+ #define BROTLI_LAST_ERROR_CODE BROTLI_DECODER_ERROR_UNREACHABLE
81
81
 
82
- /* Creates the instance of BrotliState and initializes it. |alloc_func| and
83
- |free_func| MUST be both zero or both non-zero. In the case they are both
82
+ /* Creates the instance of BrotliDecoderState and initializes it. |alloc_func|
83
+ and |free_func| MUST be both zero or both non-zero. In the case they are both
84
84
  zero, default memory allocators are used. |opaque| is passed to |alloc_func|
85
85
  and |free_func| when they are called. */
86
- BrotliState* BrotliCreateState(
86
+ BrotliDecoderState* BrotliDecoderCreateInstance(
87
87
  brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
88
88
 
89
- /* Deinitializes and frees BrotliState instance. */
90
- void BrotliDestroyState(BrotliState* state);
91
-
92
- /* Sets |*decoded_size| to the decompressed size of the given encoded stream.
93
- This function only works if the encoded buffer has a single meta block,
94
- or if it has two meta-blocks, where the first is uncompressed and the
95
- second is empty.
96
- Returns 1 on success, 0 on failure. */
97
- int BrotliDecompressedSize(size_t encoded_size,
98
- const uint8_t* encoded_buffer,
99
- size_t* decoded_size);
89
+ /* Deinitializes and frees BrotliDecoderState instance. */
90
+ void BrotliDecoderDestroyInstance(BrotliDecoderState* state);
100
91
 
101
92
  /* Decompresses the data in |encoded_buffer| into |decoded_buffer|, and sets
102
93
  |*decoded_size| to the decompressed length. */
103
- BrotliResult BrotliDecompressBuffer(size_t encoded_size,
104
- const uint8_t* encoded_buffer,
105
- size_t* decoded_size,
106
- uint8_t* decoded_buffer);
94
+ BrotliDecoderResult BrotliDecoderDecompress(
95
+ size_t encoded_size, const uint8_t* encoded_buffer, size_t* decoded_size,
96
+ uint8_t* decoded_buffer);
107
97
 
108
98
  /* Decompresses the data. Supports partial input and output.
109
99
 
@@ -120,12 +110,9 @@ BrotliResult BrotliDecompressBuffer(size_t encoded_size,
120
110
 
121
111
  Input is never overconsumed, so |next_in| and |available_in| could be passed
122
112
  to the next consumer after decoding is complete. */
123
- BrotliResult BrotliDecompressStream(size_t* available_in,
124
- const uint8_t** next_in,
125
- size_t* available_out,
126
- uint8_t** next_out,
127
- size_t* total_out,
128
- BrotliState* s);
113
+ BrotliDecoderResult BrotliDecoderDecompressStream(
114
+ BrotliDecoderState* s, size_t* available_in, const uint8_t** next_in,
115
+ size_t* available_out, uint8_t** next_out, size_t* total_out);
129
116
 
130
117
  /* Fills the new state with a dictionary for LZ77, warming up the ringbuffer,
131
118
  e.g. for custom static dictionaries for data formats.
@@ -133,27 +120,66 @@ BrotliResult BrotliDecompressStream(size_t* available_in,
133
120
  |size| should be less or equal to 2^24 (16MiB), otherwise the dictionary will
134
121
  be ignored. The dictionary must exist in memory until decoding is done and
135
122
  is owned by the caller. To use:
136
- 1) Allocate and initialize state with BrotliCreateState
123
+ 1) Allocate and initialize state with BrotliCreateInstance
137
124
  2) Use BrotliSetCustomDictionary
138
125
  3) Use BrotliDecompressStream
139
126
  4) Clean up and free state with BrotliDestroyState
140
127
  */
141
- void BrotliSetCustomDictionary(
142
- size_t size, const uint8_t* dict, BrotliState* s);
128
+ void BrotliDecoderSetCustomDictionary(
129
+ BrotliDecoderState* s, size_t size, const uint8_t* dict);
130
+
131
+ /* Returns true, if decoder has some unconsumed output.
132
+ Otherwise returns false. */
133
+ BROTLI_BOOL BrotliDecoderHasMoreOutput(const BrotliDecoderState* s);
143
134
 
144
- /* Returns 1, if s is in a state where we have not read any input bytes yet,
145
- and 0 otherwise */
146
- int BrotliStateIsStreamStart(const BrotliState* s);
135
+ /* Returns true, if decoder has already received some input bytes.
136
+ Otherwise returns false. */
137
+ BROTLI_BOOL BrotliDecoderIsUsed(const BrotliDecoderState* s);
147
138
 
148
- /* Returns 1, if s is in a state where we reached the end of the input and
149
- produced all of the output, and 0 otherwise. */
150
- int BrotliStateIsStreamEnd(const BrotliState* s);
139
+ /* Returns true, if decoder is in a state where we reached the end of the input
140
+ and produced all of the output; returns false otherwise. */
141
+ BROTLI_BOOL BrotliDecoderIsFinished(const BrotliDecoderState* s);
151
142
 
152
143
  /* Returns detailed error code after BrotliDecompressStream returns
153
- BROTLI_RESULT_ERROR. */
154
- BrotliErrorCode BrotliGetErrorCode(const BrotliState* s);
144
+ BROTLI_DECODER_RESULT_ERROR. */
145
+ BrotliDecoderErrorCode BrotliDecoderGetErrorCode(const BrotliDecoderState* s);
146
+
147
+ const char* BrotliDecoderErrorString(BrotliDecoderErrorCode c);
155
148
 
149
+ /* DEPRECATED >>> */
150
+ typedef enum {
151
+ BROTLI_RESULT_ERROR = 0,
152
+ BROTLI_RESULT_SUCCESS = 1,
153
+ BROTLI_RESULT_NEEDS_MORE_INPUT = 2,
154
+ BROTLI_RESULT_NEEDS_MORE_OUTPUT = 3
155
+ } BrotliResult;
156
+ typedef enum {
157
+ #define _BROTLI_COMMA ,
158
+ #define _BROTLI_ERROR_CODE_ENUM_ITEM(PREFIX, NAME, CODE) \
159
+ BROTLI ## PREFIX ## NAME = CODE
160
+ BROTLI_DECODER_ERROR_CODES_LIST(_BROTLI_ERROR_CODE_ENUM_ITEM, _BROTLI_COMMA)
161
+ #undef _BROTLI_ERROR_CODE_ENUM_ITEM
162
+ #undef _BROTLI_COMMA
163
+ } BrotliErrorCode;
164
+ typedef struct BrotliStateStruct BrotliState;
165
+ BrotliState* BrotliCreateState(
166
+ brotli_alloc_func alloc, brotli_free_func free, void* opaque);
167
+ void BrotliDestroyState(BrotliState* state);
168
+ BROTLI_BOOL BrotliDecompressedSize(
169
+ size_t encoded_size, const uint8_t* encoded_buffer, size_t* decoded_size);
170
+ BrotliResult BrotliDecompressBuffer(
171
+ size_t encoded_size, const uint8_t* encoded_buffer, size_t* decoded_size,
172
+ uint8_t* decoded_buffer);
173
+ BrotliResult BrotliDecompressStream(
174
+ size_t* available_in, const uint8_t** next_in, size_t* available_out,
175
+ uint8_t** next_out, size_t* total_out, BrotliState* s);
176
+ void BrotliSetCustomDictionary(
177
+ size_t size, const uint8_t* dict, BrotliState* s);
178
+ BROTLI_BOOL BrotliStateIsStreamStart(const BrotliState* s);
179
+ BROTLI_BOOL BrotliStateIsStreamEnd(const BrotliState* s);
180
+ BrotliErrorCode BrotliGetErrorCode(const BrotliState* s);
156
181
  const char* BrotliErrorString(BrotliErrorCode c);
182
+ /* <<< DEPRECATED */
157
183
 
158
184
  #if defined(__cplusplus) || defined(c_plusplus)
159
185
  } /* extern "C" */
@@ -10,8 +10,9 @@
10
10
 
11
11
  #include <string.h> /* memcpy, memset */
12
12
 
13
+ #include "../common/constants.h"
14
+ #include "../common/types.h"
13
15
  #include "./port.h"
14
- #include "./types.h"
15
16
 
16
17
  #if defined(__cplusplus) || defined(c_plusplus)
17
18
  extern "C" {
@@ -108,7 +109,7 @@ void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* table,
108
109
  uint32_t key_step; /* prefix code addend */
109
110
  int step; /* step size to replicate values in current table */
110
111
  int table_size; /* size of current table */
111
- int sorted[18]; /* symbols sorted by code length */
112
+ int sorted[BROTLI_CODE_LENGTH_CODES]; /* symbols sorted by code length */
112
113
  /* offsets in sorted table for each length */
113
114
  int offset[BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH + 1];
114
115
  int bits;
@@ -125,10 +126,10 @@ void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* table,
125
126
  bits++;
126
127
  });
127
128
  /* Symbols with code length 0 are placed after all other symbols. */
128
- offset[0] = 17;
129
+ offset[0] = BROTLI_CODE_LENGTH_CODES - 1;
129
130
 
130
131
  /* sort symbols by length, by symbol order within each length */
131
- symbol = 18;
132
+ symbol = BROTLI_CODE_LENGTH_CODES;
132
133
  do {
133
134
  BROTLI_REPEAT(6, {
134
135
  symbol--;
@@ -9,7 +9,7 @@
9
9
  #ifndef BROTLI_DEC_HUFFMAN_H_
10
10
  #define BROTLI_DEC_HUFFMAN_H_
11
11
 
12
- #include "./types.h"
12
+ #include "../common/types.h"
13
13
  #include "./port.h"
14
14
 
15
15
  #if defined(__cplusplus) || defined(c_plusplus)
@@ -18,16 +18,16 @@ extern "C" {
18
18
 
19
19
  #define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
20
20
 
21
- /* For current format this constant equals to kNumInsertAndCopyCodes */
22
- #define BROTLI_HUFFMAN_MAX_CODE_LENGTHS_SIZE 704
23
-
24
21
  /* Maximum possible Huffman table size for an alphabet size of (index * 32),
25
22
  * max code length 15 and root table bits 8. */
26
23
  static const uint16_t kMaxHuffmanTableSize[] = {
27
24
  256, 402, 436, 468, 500, 534, 566, 598, 630, 662, 694, 726, 758, 790, 822,
28
25
  854, 886, 920, 952, 984, 1016, 1048, 1080};
26
+ /* BROTLI_NUM_BLOCK_LEN_SYMBOLS == 26 */
29
27
  #define BROTLI_HUFFMAN_MAX_SIZE_26 396
28
+ /* BROTLI_MAX_BLOCK_TYPE_SYMBOLS == 258 */
30
29
  #define BROTLI_HUFFMAN_MAX_SIZE_258 632
30
+ /* BROTLI_MAX_CONTEXT_MAP_SYMBOLS == 272 */
31
31
  #define BROTLI_HUFFMAN_MAX_SIZE_272 646
32
32
 
33
33
  #define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
@@ -29,18 +29,7 @@
29
29
  #include <stdio.h>
30
30
  #endif
31
31
 
32
- /* Compatibility with non-clang compilers. */
33
- #ifndef __has_builtin
34
- #define __has_builtin(x) 0
35
- #endif
36
-
37
- #ifndef __has_attribute
38
- #define __has_attribute(x) 0
39
- #endif
40
-
41
- #ifndef __has_feature
42
- #define __has_feature(x) 0
43
- #endif
32
+ #include "../common/port.h"
44
33
 
45
34
  #if defined(__arm__) || defined(__thumb__) || \
46
35
  defined(_M_ARM) || defined(_M_ARMT)
@@ -66,26 +55,6 @@
66
55
  #define BROTLI_TARGET_POWERPC64
67
56
  #endif
68
57
 
69
- #if defined(__GNUC__) && defined(__GNUC_MINOR__)
70
- #define BROTLI_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
71
- #else
72
- #define BROTLI_GCC_VERSION 0
73
- #endif
74
-
75
- #if defined(__ICC)
76
- #define BROTLI_ICC_VERSION __ICC
77
- #else
78
- #define BROTLI_ICC_VERSION 0
79
- #endif
80
-
81
- #if defined(BROTLI_BUILD_MODERN_COMPILER)
82
- #define BROTLI_MODERN_COMPILER 1
83
- #elif (BROTLI_GCC_VERSION > 300) || (BROTLI_ICC_VERSION >= 1600)
84
- #define BROTLI_MODERN_COMPILER 1
85
- #else
86
- #define BROTLI_MODERN_COMPILER 0
87
- #endif
88
-
89
58
  #ifdef BROTLI_BUILD_PORTABLE
90
59
  #define BROTLI_ALIGNED_READ (!!1)
91
60
  #elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \
@@ -96,31 +65,6 @@
96
65
  #define BROTLI_ALIGNED_READ (!!1)
97
66
  #endif
98
67
 
99
- /* Define "PREDICT_TRUE" and "PREDICT_FALSE" macros for capable compilers.
100
-
101
- To apply compiler hint, enclose the branching condition into macros, like this:
102
-
103
- if (PREDICT_TRUE(zero == 0)) {
104
- // main execution path
105
- } else {
106
- // compiler should place this code outside of main execution path
107
- }
108
-
109
- OR:
110
-
111
- if (PREDICT_FALSE(something_rare_or_unexpected_happens)) {
112
- // compiler should place this code outside of main execution path
113
- }
114
-
115
- */
116
- #if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_expect)
117
- #define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
118
- #define PREDICT_FALSE(x) (__builtin_expect(x, 0))
119
- #else
120
- #define PREDICT_FALSE(x) (x)
121
- #define PREDICT_TRUE(x) (x)
122
- #endif
123
-
124
68
  /* IS_CONSTANT macros returns true for compile-time constant expressions. */
125
69
  #if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_constant_p)
126
70
  #define IS_CONSTANT(x) (!!__builtin_constant_p(x))
@@ -128,35 +72,6 @@ OR:
128
72
  #define IS_CONSTANT(x) (!!0)
129
73
  #endif
130
74
 
131
- #if BROTLI_MODERN_COMPILER || __has_attribute(always_inline)
132
- #define ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))
133
- #else
134
- #define ATTRIBUTE_ALWAYS_INLINE
135
- #endif
136
-
137
- #if defined(_WIN32) || defined(__CYGWIN__)
138
- #define ATTRIBUTE_VISIBILITY_HIDDEN
139
- #elif BROTLI_MODERN_COMPILER || __has_attribute(visibility)
140
- #define ATTRIBUTE_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden")))
141
- #else
142
- #define ATTRIBUTE_VISIBILITY_HIDDEN
143
- #endif
144
-
145
- #ifndef BROTLI_INTERNAL
146
- #define BROTLI_INTERNAL ATTRIBUTE_VISIBILITY_HIDDEN
147
- #endif
148
-
149
- #ifndef _MSC_VER
150
- #if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \
151
- __STDC_VERSION__ >= 199901L
152
- #define BROTLI_INLINE inline ATTRIBUTE_ALWAYS_INLINE
153
- #else
154
- #define BROTLI_INLINE
155
- #endif
156
- #else /* _MSC_VER */
157
- #define BROTLI_INLINE __forceinline
158
- #endif /* _MSC_VER */
159
-
160
75
  #ifdef BROTLI_ENABLE_LOG
161
76
  #define BROTLI_DCHECK(x) assert(x)
162
77
  #define BROTLI_LOG(x) printf x
@@ -166,7 +81,7 @@ OR:
166
81
  #endif
167
82
 
168
83
  #if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG)
169
- static inline void BrotliDump(const char* f, int l, const char* fn) {
84
+ static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) {
170
85
  fprintf(stderr, "%s:%d (%s)\n", f, l, fn);
171
86
  fflush(stderr);
172
87
  }
@@ -211,12 +126,6 @@ static inline void BrotliDump(const char* f, int l, const char* fn) {
211
126
  #define BROTLI_LITTLE_ENDIAN 0
212
127
  #endif
213
128
 
214
- #if BROTLI_MODERN_COMPILER || __has_attribute(noinline)
215
- #define BROTLI_NOINLINE __attribute__((noinline))
216
- #else
217
- #define BROTLI_NOINLINE
218
- #endif
219
-
220
129
  #define BROTLI_REPEAT(N, X) { \
221
130
  if ((N & 1) != 0) {X;} \
222
131
  if ((N & 2) != 0) {X; X;} \
@@ -247,6 +156,4 @@ static BROTLI_INLINE unsigned BrotliRBit(unsigned input) {
247
156
  X = NULL; \
248
157
  }
249
158
 
250
- #define BROTLI_UNUSED(X) (void)(X)
251
-
252
159
  #endif /* BROTLI_DEC_PORT_H_ */
@@ -11,7 +11,8 @@
11
11
  #ifndef BROTLI_DEC_PREFIX_H_
12
12
  #define BROTLI_DEC_PREFIX_H_
13
13
 
14
- #include "./types.h"
14
+ #include "../common/constants.h"
15
+ #include "../common/types.h"
15
16
 
16
17
  /* Represents the range of values belonging to a prefix code: */
17
18
  /* [offset, offset + 2^nbits) */
@@ -20,7 +21,8 @@ struct PrefixCodeRange {
20
21
  uint8_t nbits;
21
22
  };
22
23
 
23
- static const struct PrefixCodeRange kBlockLengthPrefixCode[] = {
24
+ static const struct PrefixCodeRange
25
+ kBlockLengthPrefixCode[BROTLI_NUM_BLOCK_LEN_SYMBOLS] = {
24
26
  { 1, 2}, { 5, 2}, { 9, 2}, { 13, 2},
25
27
  { 17, 3}, { 25, 3}, { 33, 3}, { 41, 3},
26
28
  { 49, 4}, { 65, 4}, { 81, 4}, { 97, 4},
@@ -39,7 +41,7 @@ typedef struct CmdLutElement {
39
41
  uint16_t copy_len_offset;
40
42
  } CmdLutElement;
41
43
 
42
- static const CmdLutElement kCmdLut[704] = {
44
+ static const CmdLutElement kCmdLut[BROTLI_NUM_COMMAND_SYMBOLS] = {
43
45
  { 0x00, 0x00, 0, 0x00, 0x0000, 0x0002 },
44
46
  { 0x00, 0x00, 0, 0x01, 0x0000, 0x0003 },
45
47
  { 0x00, 0x00, 0, 0x02, 0x0000, 0x0004 },
@@ -8,17 +8,13 @@
8
8
 
9
9
  #include <stdlib.h> /* free, malloc */
10
10
 
11
+ #include "../common/types.h"
11
12
  #include "./huffman.h"
12
- #include "./types.h"
13
13
 
14
14
  #if defined(__cplusplus) || defined(c_plusplus)
15
15
  extern "C" {
16
16
  #endif
17
17
 
18
- /* Declared in decode.h */
19
- int BrotliStateIsStreamStart(const BrotliState* s);
20
- int BrotliStateIsStreamEnd(const BrotliState* s);
21
-
22
18
  static void* DefaultAllocFunc(void* opaque, size_t size) {
23
19
  BROTLI_UNUSED(opaque);
24
20
  return malloc(size);
@@ -29,11 +25,11 @@ static void DefaultFreeFunc(void* opaque, void* address) {
29
25
  free(address);
30
26
  }
31
27
 
32
- void BrotliStateInit(BrotliState* s) {
33
- BrotliStateInitWithCustomAllocators(s, 0, 0, 0);
28
+ void BrotliDecoderStateInit(BrotliDecoderState* s) {
29
+ BrotliDecoderStateInitWithCustomAllocators(s, 0, 0, 0);
34
30
  }
35
31
 
36
- void BrotliStateInitWithCustomAllocators(BrotliState* s,
32
+ void BrotliDecoderStateInitWithCustomAllocators(BrotliDecoderState* s,
37
33
  brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {
38
34
  if (!alloc_func) {
39
35
  s->alloc_func = DefaultAllocFunc;
@@ -100,7 +96,7 @@ void BrotliStateInitWithCustomAllocators(BrotliState* s,
100
96
  s->mtf_upper_bound = 255;
101
97
  }
102
98
 
103
- void BrotliStateMetablockBegin(BrotliState* s) {
99
+ void BrotliDecoderStateMetablockBegin(BrotliDecoderState* s) {
104
100
  s->meta_block_remaining_len = 0;
105
101
  s->block_length[0] = 1U << 28;
106
102
  s->block_length[1] = 1U << 28;
@@ -131,34 +127,25 @@ void BrotliStateMetablockBegin(BrotliState* s) {
131
127
  s->distance_hgroup.htrees = NULL;
132
128
  }
133
129
 
134
- void BrotliStateCleanupAfterMetablock(BrotliState* s) {
130
+ void BrotliDecoderStateCleanupAfterMetablock(BrotliDecoderState* s) {
135
131
  BROTLI_FREE(s, s->context_modes);
136
132
  BROTLI_FREE(s, s->context_map);
137
133
  BROTLI_FREE(s, s->dist_context_map);
138
134
 
139
- BrotliHuffmanTreeGroupRelease(s, &s->literal_hgroup);
140
- BrotliHuffmanTreeGroupRelease(s, &s->insert_copy_hgroup);
141
- BrotliHuffmanTreeGroupRelease(s, &s->distance_hgroup);
135
+ BrotliDecoderHuffmanTreeGroupRelease(s, &s->literal_hgroup);
136
+ BrotliDecoderHuffmanTreeGroupRelease(s, &s->insert_copy_hgroup);
137
+ BrotliDecoderHuffmanTreeGroupRelease(s, &s->distance_hgroup);
142
138
  }
143
139
 
144
- void BrotliStateCleanup(BrotliState* s) {
145
- BrotliStateCleanupAfterMetablock(s);
140
+ void BrotliDecoderStateCleanup(BrotliDecoderState* s) {
141
+ BrotliDecoderStateCleanupAfterMetablock(s);
146
142
 
147
143
  BROTLI_FREE(s, s->ringbuffer);
148
144
  BROTLI_FREE(s, s->block_type_trees);
149
145
  }
150
146
 
151
- int BrotliStateIsStreamStart(const BrotliState* s) {
152
- return (s->state == BROTLI_STATE_UNINITED &&
153
- BrotliGetAvailableBits(&s->br) == 0);
154
- }
155
-
156
- int BrotliStateIsStreamEnd(const BrotliState* s) {
157
- return s->state == BROTLI_STATE_DONE;
158
- }
159
-
160
- void BrotliHuffmanTreeGroupInit(BrotliState* s, HuffmanTreeGroup* group,
161
- uint32_t alphabet_size, uint32_t ntrees) {
147
+ void BrotliDecoderHuffmanTreeGroupInit(BrotliDecoderState* s,
148
+ HuffmanTreeGroup* group, uint32_t alphabet_size, uint32_t ntrees) {
162
149
  /* Pack two allocations into one */
163
150
  const size_t max_table_size = kMaxHuffmanTableSize[(alphabet_size + 31) >> 5];
164
151
  const size_t code_size = sizeof(HuffmanCode) * ntrees * max_table_size;
@@ -170,7 +157,8 @@ void BrotliHuffmanTreeGroupInit(BrotliState* s, HuffmanTreeGroup* group,
170
157
  group->htrees = (HuffmanCode**)(p + code_size);
171
158
  }
172
159
 
173
- void BrotliHuffmanTreeGroupRelease(BrotliState* s, HuffmanTreeGroup* group) {
160
+ void BrotliDecoderHuffmanTreeGroupRelease(
161
+ BrotliDecoderState* s, HuffmanTreeGroup* group) {
174
162
  BROTLI_FREE(s, group->codes);
175
163
  group->htrees = NULL;
176
164
  }
@@ -9,9 +9,10 @@
9
9
  #ifndef BROTLI_DEC_STATE_H_
10
10
  #define BROTLI_DEC_STATE_H_
11
11
 
12
+ #include "../common/constants.h"
13
+ #include "../common/types.h"
12
14
  #include "./bit_reader.h"
13
15
  #include "./huffman.h"
14
- #include "./types.h"
15
16
  #include "./port.h"
16
17
 
17
18
  #if defined(__cplusplus) || defined(c_plusplus)
@@ -93,7 +94,7 @@ typedef enum {
93
94
  BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX
94
95
  } BrotliRunningReadBlockLengthState;
95
96
 
96
- struct BrotliStateStruct {
97
+ struct BrotliDecoderStateStruct {
97
98
  BrotliRunningState state;
98
99
 
99
100
  /* This counter is reused for several disjoint loops. */
@@ -173,10 +174,10 @@ struct BrotliStateStruct {
173
174
  uint16_t* symbol_lists;
174
175
  /* Storage from symbol_lists. */
175
176
  uint16_t symbols_lists_array[BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1 +
176
- BROTLI_HUFFMAN_MAX_CODE_LENGTHS_SIZE];
177
+ BROTLI_NUM_COMMAND_SYMBOLS];
177
178
  /* Tails of symbol chains. */
178
179
  int next_symbol[32];
179
- uint8_t code_length_code_lengths[18];
180
+ uint8_t code_length_code_lengths[BROTLI_CODE_LENGTH_CODES];
180
181
  /* Population counts for the code lengths */
181
182
  uint16_t code_length_histo[16];
182
183
 
@@ -221,19 +222,22 @@ struct BrotliStateStruct {
221
222
  uint32_t trivial_literal_contexts[8]; /* 256 bits */
222
223
  };
223
224
 
224
- typedef struct BrotliStateStruct BrotliStateInternal;
225
- #define BrotliState BrotliStateInternal
226
-
227
- BROTLI_INTERNAL void BrotliStateInit(BrotliState* s);
228
- BROTLI_INTERNAL void BrotliStateInitWithCustomAllocators(BrotliState* s,
229
- brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
230
- BROTLI_INTERNAL void BrotliStateCleanup(BrotliState* s);
231
- BROTLI_INTERNAL void BrotliStateMetablockBegin(BrotliState* s);
232
- BROTLI_INTERNAL void BrotliStateCleanupAfterMetablock(BrotliState* s);
233
- BROTLI_INTERNAL void BrotliHuffmanTreeGroupInit(BrotliState* s,
234
- HuffmanTreeGroup* group, uint32_t alphabet_size, uint32_t ntrees);
235
- BROTLI_INTERNAL void BrotliHuffmanTreeGroupRelease(BrotliState* s,
236
- HuffmanTreeGroup* group);
225
+ typedef struct BrotliDecoderStateStruct BrotliDecoderStateInternal;
226
+ #define BrotliDecoderState BrotliDecoderStateInternal
227
+
228
+ BROTLI_INTERNAL void BrotliDecoderStateInit(BrotliDecoderState* s);
229
+ BROTLI_INTERNAL void BrotliDecoderStateInitWithCustomAllocators(
230
+ BrotliDecoderState* s, brotli_alloc_func alloc_func,
231
+ brotli_free_func free_func, void* opaque);
232
+ BROTLI_INTERNAL void BrotliDecoderStateCleanup(BrotliDecoderState* s);
233
+ BROTLI_INTERNAL void BrotliDecoderStateMetablockBegin(BrotliDecoderState* s);
234
+ BROTLI_INTERNAL void BrotliDecoderStateCleanupAfterMetablock(
235
+ BrotliDecoderState* s);
236
+ BROTLI_INTERNAL void BrotliDecoderHuffmanTreeGroupInit(
237
+ BrotliDecoderState* s, HuffmanTreeGroup* group, uint32_t alphabet_size,
238
+ uint32_t ntrees);
239
+ BROTLI_INTERNAL void BrotliDecoderHuffmanTreeGroupRelease(
240
+ BrotliDecoderState* s, HuffmanTreeGroup* group);
237
241
 
238
242
  #if defined(__cplusplus) || defined(c_plusplus)
239
243
  } /* extern "C" */
@@ -9,8 +9,8 @@
9
9
  #ifndef BROTLI_DEC_TRANSFORM_H_
10
10
  #define BROTLI_DEC_TRANSFORM_H_
11
11
 
12
+ #include "../common/types.h"
12
13
  #include "./port.h"
13
- #include "./types.h"
14
14
 
15
15
  #if defined(__cplusplus) || defined(c_plusplus)
16
16
  extern "C" {