multi_compress 0.3.2 → 0.3.4

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 (212) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -3
  3. data/GET_STARTED.md +3 -3
  4. data/README.md +75 -66
  5. data/THIRD_PARTY_NOTICES.md +24 -0
  6. data/ext/multi_compress/brotli_dec_static_init.c +3 -0
  7. data/ext/multi_compress/brotli_enc_static_init.c +3 -0
  8. data/ext/multi_compress/extconf.rb +79 -3
  9. data/ext/multi_compress/multi_compress.c +199 -120
  10. data/ext/multi_compress/vendor/.vendored +2 -2
  11. data/ext/multi_compress/vendor/brotli/LICENSE +19 -0
  12. data/ext/multi_compress/vendor/brotli/c/common/constants.c +7 -7
  13. data/ext/multi_compress/vendor/brotli/c/common/constants.h +2 -5
  14. data/ext/multi_compress/vendor/brotli/c/common/context.c +2 -2
  15. data/ext/multi_compress/vendor/brotli/c/common/context.h +1 -2
  16. data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +4 -5856
  17. data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +1 -2
  18. data/ext/multi_compress/vendor/brotli/c/common/dictionary_inc.h +5847 -0
  19. data/ext/multi_compress/vendor/brotli/c/common/platform.c +0 -4
  20. data/ext/multi_compress/vendor/brotli/c/common/platform.h +182 -43
  21. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +3 -7
  22. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +1 -1
  23. data/ext/multi_compress/vendor/brotli/c/common/static_init.h +56 -0
  24. data/ext/multi_compress/vendor/brotli/c/common/transform.c +6 -4
  25. data/ext/multi_compress/vendor/brotli/c/common/transform.h +1 -2
  26. data/ext/multi_compress/vendor/brotli/c/common/version.h +3 -3
  27. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +2 -3
  28. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +0 -4
  29. data/ext/multi_compress/vendor/brotli/c/dec/decode.c +128 -39
  30. data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +2 -5
  31. data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +0 -2
  32. data/ext/multi_compress/vendor/brotli/c/dec/prefix.c +67 -0
  33. data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +18 -708
  34. data/ext/multi_compress/vendor/brotli/c/dec/prefix_inc.h +707 -0
  35. data/ext/multi_compress/vendor/brotli/c/dec/state.c +18 -15
  36. data/ext/multi_compress/vendor/brotli/c/dec/state.h +2 -6
  37. data/ext/multi_compress/vendor/brotli/c/dec/static_init.c +53 -0
  38. data/ext/multi_compress/vendor/brotli/c/dec/static_init.h +30 -0
  39. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +32 -8
  40. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +1 -5
  41. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +15 -15
  42. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +1 -5
  43. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +28 -4
  44. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +8 -40
  45. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +1 -1
  46. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +9 -12
  47. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +0 -3
  48. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +14 -8
  49. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +10 -9
  50. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +0 -6
  51. data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +0 -2
  52. data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +0 -2
  53. data/ext/multi_compress/vendor/brotli/c/enc/command.c +1 -1
  54. data/ext/multi_compress/vendor/brotli/c/enc/command.h +8 -10
  55. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +3 -5
  56. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +1 -4
  57. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +3 -13
  58. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +0 -2
  59. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +5 -15
  60. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -2
  61. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +127 -1830
  62. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +23 -3
  63. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash_inc.h +1829 -0
  64. data/ext/multi_compress/vendor/brotli/c/enc/encode.c +77 -52
  65. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +9 -7
  66. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +2 -4
  67. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +3 -6
  68. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +2 -4
  69. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +18 -12
  70. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +1 -1
  71. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +2 -3
  72. data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +0 -2
  73. data/ext/multi_compress/vendor/brotli/c/enc/hash.h +38 -31
  74. data/ext/multi_compress/vendor/brotli/c/enc/hash_base.h +38 -0
  75. data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +11 -1
  76. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +24 -7
  77. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_simd_inc.h +304 -0
  78. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +30 -11
  79. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +4 -0
  80. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_simd_inc.h +278 -0
  81. data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +1 -0
  82. data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +0 -4
  83. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +4 -6
  84. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +0 -2
  85. data/ext/multi_compress/vendor/brotli/c/enc/matching_tag_mask.h +69 -0
  86. data/ext/multi_compress/vendor/brotli/c/enc/memory.c +0 -5
  87. data/ext/multi_compress/vendor/brotli/c/enc/memory.h +0 -4
  88. data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +7 -9
  89. data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +3 -3
  90. data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +4 -4
  91. data/ext/multi_compress/vendor/brotli/c/enc/params.h +0 -1
  92. data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +0 -2
  93. data/ext/multi_compress/vendor/brotli/c/enc/quality.h +17 -10
  94. data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +1 -4
  95. data/ext/multi_compress/vendor/brotli/c/enc/state.h +2 -2
  96. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +5 -11
  97. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +1 -3
  98. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.c +224 -0
  99. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +20 -5837
  100. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut_inc.h +5830 -0
  101. data/ext/multi_compress/vendor/brotli/c/enc/static_init.c +59 -0
  102. data/ext/multi_compress/vendor/brotli/c/enc/static_init.h +30 -0
  103. data/ext/multi_compress/vendor/brotli/c/enc/static_init_lazy.cc +26 -0
  104. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +1 -1
  105. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +0 -2
  106. data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +0 -2
  107. data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +1 -1
  108. data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +5 -1
  109. data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +4 -7
  110. data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +2 -2
  111. data/ext/multi_compress/vendor/lz4/LICENSE +12 -0
  112. data/ext/multi_compress/vendor/zstd/COPYING +339 -0
  113. data/ext/multi_compress/vendor/zstd/LICENSE +30 -0
  114. data/ext/multi_compress/vendor/zstd/lib/Makefile +67 -35
  115. data/ext/multi_compress/vendor/zstd/lib/README.md +33 -2
  116. data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
  117. data/ext/multi_compress/vendor/zstd/lib/common/bits.h +205 -0
  118. data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +84 -108
  119. data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +170 -41
  120. data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +37 -1
  121. data/ext/multi_compress/vendor/zstd/lib/common/debug.c +7 -1
  122. data/ext/multi_compress/vendor/zstd/lib/common/debug.h +21 -21
  123. data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +12 -40
  124. data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +10 -2
  125. data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +46 -47
  126. data/ext/multi_compress/vendor/zstd/lib/common/fse.h +8 -100
  127. data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +28 -116
  128. data/ext/multi_compress/vendor/zstd/lib/common/huf.h +79 -166
  129. data/ext/multi_compress/vendor/zstd/lib/common/mem.h +46 -66
  130. data/ext/multi_compress/vendor/zstd/lib/common/pool.c +27 -11
  131. data/ext/multi_compress/vendor/zstd/lib/common/pool.h +8 -11
  132. data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +45 -11
  133. data/ext/multi_compress/vendor/zstd/lib/common/threading.c +74 -14
  134. data/ext/multi_compress/vendor/zstd/lib/common/threading.h +5 -18
  135. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +5 -11
  136. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +2411 -1003
  137. data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +1 -36
  138. data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +13 -1
  139. data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +13 -182
  140. data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +6 -13
  141. data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +1 -1
  142. data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +15 -131
  143. data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +11 -1
  144. data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +8 -1
  145. data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +283 -189
  146. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +2419 -903
  147. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +423 -245
  148. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +116 -40
  149. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +16 -8
  150. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +10 -10
  151. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +8 -7
  152. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +254 -139
  153. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  154. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +184 -95
  155. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +163 -81
  156. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +18 -14
  157. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +507 -197
  158. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +7 -14
  159. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +579 -484
  160. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +133 -65
  161. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +61 -40
  162. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +7 -15
  163. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +1 -1
  164. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +352 -218
  165. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +37 -21
  166. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +238 -0
  167. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.h +33 -0
  168. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +239 -175
  169. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +5 -16
  170. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +543 -488
  171. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +78 -61
  172. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +4 -4
  173. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +1 -1
  174. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +295 -115
  175. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +430 -293
  176. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +7 -2
  177. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +11 -7
  178. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +1 -1
  179. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +1 -1
  180. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +1 -1
  181. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +3 -1
  182. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +95 -46
  183. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +3 -9
  184. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +0 -10
  185. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +4 -4
  186. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +25 -97
  187. data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +1 -1
  188. data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +1 -1
  189. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +38 -1
  190. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +19 -50
  191. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +1 -1
  192. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +27 -80
  193. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +1 -1
  194. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +28 -83
  195. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +1 -1
  196. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +25 -74
  197. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +1 -1
  198. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +31 -76
  199. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +1 -1
  200. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +44 -88
  201. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +1 -1
  202. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +33 -84
  203. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +1 -1
  204. data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +65 -33
  205. data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +5 -5
  206. data/ext/multi_compress/vendor/zstd/lib/module.modulemap +13 -3
  207. data/ext/multi_compress/vendor/zstd/lib/zdict.h +65 -36
  208. data/ext/multi_compress/vendor/zstd/lib/zstd.h +890 -267
  209. data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +28 -16
  210. data/lib/multi_compress/version.rb +1 -1
  211. data/lib/multi_compress.rb +80 -41
  212. metadata +29 -2
@@ -95,6 +95,97 @@ typedef enum { LZ4_FORMAT_BLOCK = 0, LZ4_FORMAT_FRAME = 1 } lz4_format_t;
95
95
 
96
96
  #define MC_NUM_ALGOS 3
97
97
 
98
+ static pthread_once_t zstd_tls_once = PTHREAD_ONCE_INIT;
99
+ static pthread_key_t zstd_cctx_key;
100
+ static pthread_key_t zstd_dctx_key;
101
+
102
+ static void zstd_tls_free_cctx(void *ptr) {
103
+ if (ptr)
104
+ ZSTD_freeCCtx((ZSTD_CCtx *)ptr);
105
+ }
106
+
107
+ static void zstd_tls_free_dctx(void *ptr) {
108
+ if (ptr)
109
+ ZSTD_freeDCtx((ZSTD_DCtx *)ptr);
110
+ }
111
+
112
+ static void zstd_tls_init(void) {
113
+ if (pthread_key_create(&zstd_cctx_key, zstd_tls_free_cctx) != 0)
114
+ abort();
115
+ if (pthread_key_create(&zstd_dctx_key, zstd_tls_free_dctx) != 0)
116
+ abort();
117
+ }
118
+
119
+ static ZSTD_CCtx *zstd_tls_get_cctx(void) {
120
+ pthread_once(&zstd_tls_once, zstd_tls_init);
121
+
122
+ ZSTD_CCtx *cctx = (ZSTD_CCtx *)pthread_getspecific(zstd_cctx_key);
123
+ if (cctx)
124
+ return cctx;
125
+
126
+ cctx = ZSTD_createCCtx();
127
+ if (!cctx)
128
+ return NULL;
129
+
130
+ if (pthread_setspecific(zstd_cctx_key, cctx) != 0) {
131
+ ZSTD_freeCCtx(cctx);
132
+ return NULL;
133
+ }
134
+
135
+ return cctx;
136
+ }
137
+
138
+ static ZSTD_DCtx *zstd_tls_get_dctx(void) {
139
+ pthread_once(&zstd_tls_once, zstd_tls_init);
140
+
141
+ ZSTD_DCtx *dctx = (ZSTD_DCtx *)pthread_getspecific(zstd_dctx_key);
142
+ if (dctx)
143
+ return dctx;
144
+
145
+ dctx = ZSTD_createDCtx();
146
+ if (!dctx)
147
+ return NULL;
148
+
149
+ if (pthread_setspecific(zstd_dctx_key, dctx) != 0) {
150
+ ZSTD_freeDCtx(dctx);
151
+ return NULL;
152
+ }
153
+
154
+ return dctx;
155
+ }
156
+
157
+ static size_t zstd_compress_cached(char *dst, size_t dst_cap, const char *src, size_t src_len,
158
+ int level, ZSTD_CDict *cdict, int *ctx_error) {
159
+ *ctx_error = 0;
160
+
161
+ ZSTD_CCtx *cctx = zstd_tls_get_cctx();
162
+ if (!cctx) {
163
+ *ctx_error = 1;
164
+ return 0;
165
+ }
166
+
167
+ if (cdict)
168
+ return ZSTD_compress_usingCDict(cctx, dst, dst_cap, src, src_len, cdict);
169
+
170
+ return ZSTD_compressCCtx(cctx, dst, dst_cap, src, src_len, level);
171
+ }
172
+
173
+ static size_t zstd_decompress_cached(void *dst, size_t dst_cap, const void *src, size_t src_len,
174
+ ZSTD_DDict *ddict, int *ctx_error) {
175
+ *ctx_error = 0;
176
+
177
+ ZSTD_DCtx *dctx = zstd_tls_get_dctx();
178
+ if (!dctx) {
179
+ *ctx_error = 1;
180
+ return 0;
181
+ }
182
+
183
+ if (ddict)
184
+ return ZSTD_decompress_usingDDict(dctx, dst, dst_cap, src, src_len, ddict);
185
+
186
+ return ZSTD_decompressDCtx(dctx, dst, dst_cap, src, src_len);
187
+ }
188
+
98
189
  _Static_assert(ALGO_BROTLI == MC_NUM_ALGOS - 1,
99
190
  "compress_algo_t must be contiguous [0..MC_NUM_ALGOS-1]");
100
191
 
@@ -439,8 +530,6 @@ static inline VALUE rb_binary_str_buf_new(long capa) {
439
530
  static inline VALUE rb_binary_str_buf_reserve(long capa) {
440
531
  VALUE str = rb_str_buf_new(capa);
441
532
  rb_enc_associate(str, binary_encoding);
442
- if (capa > 0)
443
- rb_str_modify_expand(str, capa + 1);
444
533
  return str;
445
534
  }
446
535
 
@@ -689,13 +778,19 @@ static inline size_t fiber_maybe_yield(size_t bytes_since_yield, size_t just_pro
689
778
  return bytes_since_yield;
690
779
  }
691
780
 
692
- #define DICT_CDICT_CACHE_SIZE 22
693
- _Static_assert(DICT_CDICT_CACHE_SIZE > 0, "CDict cache needs at least one slot");
781
+ #define DICT_ZSTD_MIN_LEVEL 1
782
+ #define DICT_ZSTD_MAX_LEVEL 22
783
+ #define DICT_CDICT_CACHE_SIZE (DICT_ZSTD_MAX_LEVEL + 1)
784
+ _Static_assert(DICT_CDICT_CACHE_SIZE > DICT_ZSTD_MAX_LEVEL,
785
+ "CDict cache needs one slot for every accepted zstd level");
694
786
 
695
- typedef struct {
696
- int level;
697
- ZSTD_CDict *cdict;
698
- } cdict_cache_entry_t;
787
+ #if defined(__GNUC__) || defined(__clang__)
788
+ #define MC_HAS_ATOMIC_PTR 1
789
+ #define MC_ATOMIC_LOAD_PTR(ptr) __atomic_load_n((ptr), __ATOMIC_ACQUIRE)
790
+ #define MC_ATOMIC_STORE_PTR(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_RELEASE)
791
+ #else
792
+ #define MC_HAS_ATOMIC_PTR 0
793
+ #endif
699
794
 
700
795
  struct dictionary_s {
701
796
  compress_algo_t algo;
@@ -703,8 +798,7 @@ struct dictionary_s {
703
798
  size_t size;
704
799
  pthread_mutex_t cache_mutex;
705
800
 
706
- cdict_cache_entry_t cdict_cache[DICT_CDICT_CACHE_SIZE];
707
- int cdict_cache_count;
801
+ ZSTD_CDict *cdict_cache[DICT_CDICT_CACHE_SIZE];
708
802
 
709
803
  ZSTD_DDict *ddict;
710
804
  };
@@ -713,9 +807,9 @@ static void dict_free(void *ptr) {
713
807
  dictionary_t *dict = (dictionary_t *)ptr;
714
808
  if (!dict)
715
809
  return;
716
- for (int i = 0; i < dict->cdict_cache_count; i++) {
717
- if (dict->cdict_cache[i].cdict)
718
- ZSTD_freeCDict(dict->cdict_cache[i].cdict);
810
+ for (int i = DICT_ZSTD_MIN_LEVEL; i <= DICT_ZSTD_MAX_LEVEL; i++) {
811
+ if (dict->cdict_cache[i])
812
+ ZSTD_freeCDict(dict->cdict_cache[i]);
719
813
  }
720
814
  if (dict->ddict)
721
815
  ZSTD_freeDDict(dict->ddict);
@@ -732,9 +826,9 @@ static size_t dict_memsize(const void *ptr) {
732
826
 
733
827
  size_t total = sizeof(dictionary_t) + d->size;
734
828
  if (d->algo == ALGO_ZSTD) {
735
- for (int i = 0; i < d->cdict_cache_count; i++) {
736
- if (d->cdict_cache[i].cdict)
737
- total += ZSTD_sizeof_CDict(d->cdict_cache[i].cdict);
829
+ for (int i = DICT_ZSTD_MIN_LEVEL; i <= DICT_ZSTD_MAX_LEVEL; i++) {
830
+ if (d->cdict_cache[i])
831
+ total += ZSTD_sizeof_CDict(d->cdict_cache[i]);
738
832
  }
739
833
  if (d->ddict)
740
834
  total += ZSTD_sizeof_DDict(d->ddict);
@@ -756,17 +850,18 @@ static VALUE dict_alloc(VALUE klass) {
756
850
  }
757
851
 
758
852
  static ZSTD_CDict *dict_get_cdict(dictionary_t *dict, int level) {
759
- ZSTD_CDict *existing = NULL;
853
+ if (MC_UNLIKELY(level < DICT_ZSTD_MIN_LEVEL || level > DICT_ZSTD_MAX_LEVEL))
854
+ rb_raise(eLevelError, "zstd level must be %d..%d, got %d", DICT_ZSTD_MIN_LEVEL,
855
+ DICT_ZSTD_MAX_LEVEL, level);
760
856
 
857
+ ZSTD_CDict *existing;
858
+ #if MC_HAS_ATOMIC_PTR
859
+ existing = MC_ATOMIC_LOAD_PTR(&dict->cdict_cache[level]);
860
+ #else
761
861
  pthread_mutex_lock(&dict->cache_mutex);
762
- for (int i = 0; i < dict->cdict_cache_count; i++) {
763
- if (dict->cdict_cache[i].level == level) {
764
- existing = dict->cdict_cache[i].cdict;
765
- break;
766
- }
767
- }
862
+ existing = dict->cdict_cache[level];
768
863
  pthread_mutex_unlock(&dict->cache_mutex);
769
-
864
+ #endif
770
865
  if (existing)
771
866
  return existing;
772
867
 
@@ -775,34 +870,31 @@ static ZSTD_CDict *dict_get_cdict(dictionary_t *dict, int level) {
775
870
  return NULL;
776
871
 
777
872
  pthread_mutex_lock(&dict->cache_mutex);
778
- for (int i = 0; i < dict->cdict_cache_count; i++) {
779
- if (dict->cdict_cache[i].level == level) {
780
- existing = dict->cdict_cache[i].cdict;
781
- pthread_mutex_unlock(&dict->cache_mutex);
782
- ZSTD_freeCDict(cdict);
783
- return existing;
784
- }
785
- }
786
-
787
- if (dict->cdict_cache_count >= DICT_CDICT_CACHE_SIZE) {
873
+ existing = dict->cdict_cache[level];
874
+ if (!existing) {
875
+ #if MC_HAS_ATOMIC_PTR
876
+ MC_ATOMIC_STORE_PTR(&dict->cdict_cache[level], cdict);
877
+ #else
878
+ dict->cdict_cache[level] = cdict;
879
+ #endif
788
880
  pthread_mutex_unlock(&dict->cache_mutex);
789
- ZSTD_freeCDict(cdict);
790
- rb_raise(eError, "zstd dictionary cdict cache exhausted");
881
+ return cdict;
791
882
  }
792
883
 
793
- dict->cdict_cache[dict->cdict_cache_count].level = level;
794
- dict->cdict_cache[dict->cdict_cache_count].cdict = cdict;
795
- dict->cdict_cache_count++;
796
884
  pthread_mutex_unlock(&dict->cache_mutex);
797
- return cdict;
885
+ ZSTD_freeCDict(cdict);
886
+ return existing;
798
887
  }
799
888
 
800
889
  static ZSTD_DDict *dict_get_ddict(dictionary_t *dict) {
801
890
  ZSTD_DDict *existing;
802
-
891
+ #if MC_HAS_ATOMIC_PTR
892
+ existing = MC_ATOMIC_LOAD_PTR(&dict->ddict);
893
+ #else
803
894
  pthread_mutex_lock(&dict->cache_mutex);
804
895
  existing = dict->ddict;
805
896
  pthread_mutex_unlock(&dict->cache_mutex);
897
+ #endif
806
898
  if (existing)
807
899
  return existing;
808
900
 
@@ -811,12 +903,17 @@ static ZSTD_DDict *dict_get_ddict(dictionary_t *dict) {
811
903
  return NULL;
812
904
 
813
905
  pthread_mutex_lock(&dict->cache_mutex);
814
- if (!dict->ddict) {
906
+ existing = dict->ddict;
907
+ if (!existing) {
908
+ #if MC_HAS_ATOMIC_PTR
909
+ MC_ATOMIC_STORE_PTR(&dict->ddict, created);
910
+ #else
815
911
  dict->ddict = created;
912
+ #endif
816
913
  pthread_mutex_unlock(&dict->cache_mutex);
817
914
  return created;
818
915
  }
819
- existing = dict->ddict;
916
+
820
917
  pthread_mutex_unlock(&dict->cache_mutex);
821
918
  ZSTD_freeDDict(created);
822
919
  return existing;
@@ -835,19 +932,8 @@ typedef struct {
835
932
 
836
933
  static void *zstd_compress_nogvl(void *arg) {
837
934
  zstd_compress_args_t *a = (zstd_compress_args_t *)arg;
838
- if (a->cdict) {
839
- ZSTD_CCtx *cctx = ZSTD_createCCtx();
840
- if (!cctx) {
841
- a->error = 1;
842
- return NULL;
843
- }
844
- a->result =
845
- ZSTD_compress_usingCDict(cctx, a->dst, a->dst_cap, a->src, a->src_len, a->cdict);
846
- ZSTD_freeCCtx(cctx);
847
- } else {
848
- a->result = ZSTD_compress(a->dst, a->dst_cap, a->src, a->src_len, a->level);
849
- }
850
- a->error = 0;
935
+ a->result =
936
+ zstd_compress_cached(a->dst, a->dst_cap, a->src, a->src_len, a->level, a->cdict, &a->error);
851
937
  return NULL;
852
938
  }
853
939
 
@@ -863,19 +949,7 @@ typedef struct {
863
949
 
864
950
  static void *zstd_decompress_nogvl(void *arg) {
865
951
  zstd_decompress_args_t *a = (zstd_decompress_args_t *)arg;
866
- if (a->ddict) {
867
- ZSTD_DCtx *dctx = ZSTD_createDCtx();
868
- if (!dctx) {
869
- a->error = 1;
870
- return NULL;
871
- }
872
- a->result =
873
- ZSTD_decompress_usingDDict(dctx, a->dst, a->dst_cap, a->src, a->src_len, a->ddict);
874
- ZSTD_freeDCtx(dctx);
875
- } else {
876
- a->result = ZSTD_decompress(a->dst, a->dst_cap, a->src, a->src_len);
877
- }
878
- a->error = 0;
952
+ a->result = zstd_decompress_cached(a->dst, a->dst_cap, a->src, a->src_len, a->ddict, &a->error);
879
953
  return NULL;
880
954
  }
881
955
 
@@ -1168,18 +1242,8 @@ static void *brotli_decompress_stream_fiber_nogvl(void *arg) {
1168
1242
 
1169
1243
  static void *zstd_fiber_compress_nogvl(void *arg) {
1170
1244
  zstd_fiber_compress_t *a = (zstd_fiber_compress_t *)arg;
1171
- if (a->cdict) {
1172
- ZSTD_CCtx *cctx = ZSTD_createCCtx();
1173
- if (!cctx) {
1174
- a->error = 1;
1175
- return NULL;
1176
- }
1177
- a->result =
1178
- ZSTD_compress_usingCDict(cctx, a->dst, a->dst_cap, a->src, a->src_len, a->cdict);
1179
- ZSTD_freeCCtx(cctx);
1180
- } else {
1181
- a->result = ZSTD_compress(a->dst, a->dst_cap, a->src, a->src_len, a->level);
1182
- }
1245
+ a->result =
1246
+ zstd_compress_cached(a->dst, a->dst_cap, a->src, a->src_len, a->level, a->cdict, &a->error);
1183
1247
  return NULL;
1184
1248
  }
1185
1249
 
@@ -1226,16 +1290,11 @@ static VALUE compress_compress(int argc, VALUE *argv, VALUE self) {
1226
1290
 
1227
1291
  if (slen < policy->gvl_unlock_threshold) {
1228
1292
  VALUE dst = rb_binary_str_buf_reserve(bound);
1229
- size_t csize;
1230
- if (cdict) {
1231
- ZSTD_CCtx *cctx = ZSTD_createCCtx();
1232
- if (!cctx)
1233
- rb_raise(eMemError, "zstd: failed to create context");
1234
- csize = ZSTD_compress_usingCDict(cctx, RSTRING_PTR(dst), bound, src, slen, cdict);
1235
- ZSTD_freeCCtx(cctx);
1236
- } else {
1237
- csize = ZSTD_compress(RSTRING_PTR(dst), bound, src, slen, level);
1238
- }
1293
+ int ctx_error = 0;
1294
+ size_t csize =
1295
+ zstd_compress_cached(RSTRING_PTR(dst), bound, src, slen, level, cdict, &ctx_error);
1296
+ if (ctx_error)
1297
+ rb_raise(eMemError, "zstd: failed to create context");
1239
1298
  if (ZSTD_isError(csize))
1240
1299
  rb_raise(eError, "zstd compress: %s", ZSTD_getErrorName(csize));
1241
1300
  rb_str_set_len(dst, (long)csize);
@@ -1416,8 +1475,18 @@ static VALUE compress_compress(int argc, VALUE *argv, VALUE self) {
1416
1475
  rb_raise(eMemError, "brotli: failed to prepare dictionary");
1417
1476
  }
1418
1477
 
1419
- if (!BrotliEncoderSetParameter(enc, BROTLI_PARAM_QUALITY, level) ||
1420
- !BrotliEncoderAttachPreparedDictionary(enc, pd)) {
1478
+ if (!BrotliEncoderSetParameter(enc, BROTLI_PARAM_QUALITY, level)) {
1479
+ BrotliEncoderDestroyPreparedDictionary(pd);
1480
+ BrotliEncoderDestroyInstance(enc);
1481
+ rb_raise(eError, "brotli: failed to set quality parameter");
1482
+ }
1483
+ if (!BrotliEncoderSetParameter(enc, BROTLI_PARAM_SIZE_HINT,
1484
+ slen > UINT32_MAX ? UINT32_MAX : (uint32_t)slen)) {
1485
+ BrotliEncoderDestroyPreparedDictionary(pd);
1486
+ BrotliEncoderDestroyInstance(enc);
1487
+ rb_raise(eError, "brotli: failed to set size hint parameter");
1488
+ }
1489
+ if (!BrotliEncoderAttachPreparedDictionary(enc, pd)) {
1421
1490
  BrotliEncoderDestroyPreparedDictionary(pd);
1422
1491
  BrotliEncoderDestroyInstance(enc);
1423
1492
  rb_raise(eError, "brotli: failed to attach dictionary");
@@ -1576,20 +1645,19 @@ static VALUE compress_decompress(int argc, VALUE *argv, VALUE self) {
1576
1645
  } else {
1577
1646
  VALUE dst = rb_binary_str_buf_reserve((size_t)frame_size);
1578
1647
 
1648
+ ZSTD_DDict *ddict = NULL;
1579
1649
  if (dict) {
1580
- ZSTD_DDict *ddict = dict_get_ddict(dict);
1650
+ ddict = dict_get_ddict(dict);
1581
1651
  if (!ddict)
1582
1652
  rb_raise(eMemError, "zstd: failed to create ddict");
1583
- ZSTD_DCtx *dctx = ZSTD_createDCtx();
1584
- if (!dctx)
1585
- rb_raise(eMemError, "zstd: failed to create dctx");
1586
- dsize = ZSTD_decompress_usingDDict(dctx, RSTRING_PTR(dst), (size_t)frame_size,
1587
- src, slen, ddict);
1588
- ZSTD_freeDCtx(dctx);
1589
- } else {
1590
- dsize = ZSTD_decompress(RSTRING_PTR(dst), (size_t)frame_size, src, slen);
1591
1653
  }
1592
1654
 
1655
+ int ctx_error = 0;
1656
+ dsize = zstd_decompress_cached(RSTRING_PTR(dst), (size_t)frame_size, src, slen,
1657
+ ddict, &ctx_error);
1658
+ if (ctx_error)
1659
+ rb_raise(eMemError, "zstd: failed to create dctx");
1660
+
1593
1661
  if (ZSTD_isError(dsize))
1594
1662
  rb_raise(eDataError, "zstd decompress: %s", ZSTD_getErrorName(dsize));
1595
1663
  enforce_output_and_ratio_limits(dsize, slen, limits.max_output_size,
@@ -1601,16 +1669,21 @@ static VALUE compress_decompress(int argc, VALUE *argv, VALUE self) {
1601
1669
  }
1602
1670
  }
1603
1671
 
1604
- ZSTD_DCtx *dctx = ZSTD_createDCtx();
1672
+ ZSTD_DCtx *dctx = zstd_tls_get_dctx();
1605
1673
  if (!dctx)
1606
1674
  rb_raise(eMemError, "zstd: failed to create dctx");
1607
1675
 
1676
+ {
1677
+ size_t r = ZSTD_DCtx_reset(dctx, ZSTD_reset_session_and_parameters);
1678
+ if (ZSTD_isError(r))
1679
+ rb_raise(eError, "zstd dctx reset: %s", ZSTD_getErrorName(r));
1680
+ }
1681
+
1608
1682
  if (dict) {
1609
1683
  ZSTD_DDict *ddict = dict_get_ddict(dict);
1610
1684
  if (ddict) {
1611
1685
  size_t r = ZSTD_DCtx_refDDict(dctx, ddict);
1612
1686
  if (ZSTD_isError(r)) {
1613
- ZSTD_freeDCtx(dctx);
1614
1687
  rb_raise(eError, "zstd dict ref: %s", ZSTD_getErrorName(r));
1615
1688
  }
1616
1689
  }
@@ -1629,7 +1702,6 @@ static VALUE compress_decompress(int argc, VALUE *argv, VALUE self) {
1629
1702
  while (input.pos < input.size) {
1630
1703
  if (total_out >= alloc_size) {
1631
1704
  if (alloc_size >= limits.max_output_size) {
1632
- ZSTD_freeDCtx(dctx);
1633
1705
  rb_raise(eDataError, "decompressed output exceeds limit (%zu bytes)",
1634
1706
  limits.max_output_size);
1635
1707
  }
@@ -1642,7 +1714,6 @@ static VALUE compress_decompress(int argc, VALUE *argv, VALUE self) {
1642
1714
 
1643
1715
  size_t remaining_budget = limits.max_output_size - total_out;
1644
1716
  if (remaining_budget == 0) {
1645
- ZSTD_freeDCtx(dctx);
1646
1717
  rb_raise(eDataError, "decompressed output exceeds limit (%zu bytes)",
1647
1718
  limits.max_output_size);
1648
1719
  }
@@ -1654,7 +1725,6 @@ static VALUE compress_decompress(int argc, VALUE *argv, VALUE self) {
1654
1725
  ZSTD_outBuffer output = {RSTRING_PTR(dst) + total_out, out_cap, 0};
1655
1726
  size_t ret = ZSTD_decompressStream(dctx, &output, &input);
1656
1727
  if (ZSTD_isError(ret)) {
1657
- ZSTD_freeDCtx(dctx);
1658
1728
  rb_raise(eDataError, "zstd decompress: %s", ZSTD_getErrorName(ret));
1659
1729
  }
1660
1730
  total_out = checked_add_size(total_out, output.pos,
@@ -1665,7 +1735,6 @@ static VALUE compress_decompress(int argc, VALUE *argv, VALUE self) {
1665
1735
  break;
1666
1736
  }
1667
1737
 
1668
- ZSTD_freeDCtx(dctx);
1669
1738
  rb_str_set_len(dst, total_out);
1670
1739
  RB_GC_GUARD(data);
1671
1740
  RB_GC_GUARD(dict_val);
@@ -1875,7 +1944,7 @@ static void crc32_init_tables(void) {
1875
1944
  for (uint32_t i = 0; i < 256; i++) {
1876
1945
  uint32_t crc = i;
1877
1946
  for (int j = 0; j < 8; j++) {
1878
- crc = (crc >> 1) ^ (0xEDB88320 & (-(int32_t)(crc & 1)));
1947
+ crc = (crc >> 1) ^ (0xEDB88320u & (0u - (crc & 1u)));
1879
1948
  }
1880
1949
  crc32_tables[0][i] = crc;
1881
1950
  }
@@ -2189,6 +2258,10 @@ static VALUE lz4_compress_ring_block(deflater_t *d) {
2189
2258
 
2190
2259
  write_le_u32((uint8_t *)out, (uint32_t)src_size);
2191
2260
 
2261
+ /* Keep blocks independently decodable. Switching to LZ4_*_continue would
2262
+ * require a coordinated format/decoder change that preserves dictionaries
2263
+ * across blocks.
2264
+ */
2192
2265
  int csize;
2193
2266
  if (d->level > 1) {
2194
2267
  csize = LZ4_compress_HC(block_start, out + 8, src_size, bound, d->level);
@@ -2979,13 +3052,24 @@ static VALUE inflater_write(VALUE self, VALUE chunk) {
2979
3052
  }
2980
3053
  case ALGO_LZ4: {
2981
3054
  size_t data_len = inf->lz4_buf.len - inf->lz4_buf.offset;
2982
- size_t needed = data_len + slen;
3055
+ size_t needed =
3056
+ checked_add_size(data_len, slen, "lz4 stream input buffer exceeds representable size");
2983
3057
 
2984
- if (inf->lz4_buf.offset > 0 && needed > inf->lz4_buf.cap) {
2985
- if (data_len > 0)
2986
- memmove(inf->lz4_buf.buf, inf->lz4_buf.buf + inf->lz4_buf.offset, data_len);
2987
- inf->lz4_buf.offset = 0;
2988
- inf->lz4_buf.len = data_len;
3058
+ if (needed > inf->lz4_buf.cap) {
3059
+ size_t new_cap = needed > SIZE_MAX / 2 ? needed : needed * 2;
3060
+ if (inf->lz4_buf.offset > 0) {
3061
+ char *new_buf = ALLOC_N(char, new_cap);
3062
+ if (data_len > 0)
3063
+ memcpy(new_buf, inf->lz4_buf.buf + inf->lz4_buf.offset, data_len);
3064
+ xfree(inf->lz4_buf.buf);
3065
+ inf->lz4_buf.buf = new_buf;
3066
+ inf->lz4_buf.offset = 0;
3067
+ inf->lz4_buf.len = data_len;
3068
+ inf->lz4_buf.cap = new_cap;
3069
+ } else {
3070
+ REALLOC_N(inf->lz4_buf.buf, char, new_cap);
3071
+ inf->lz4_buf.cap = new_cap;
3072
+ }
2989
3073
  } else if (inf->lz4_buf.offset > inf->lz4_buf.cap / 2) {
2990
3074
  if (data_len > 0)
2991
3075
  memmove(inf->lz4_buf.buf, inf->lz4_buf.buf + inf->lz4_buf.offset, data_len);
@@ -2993,11 +3077,6 @@ static VALUE inflater_write(VALUE self, VALUE chunk) {
2993
3077
  inf->lz4_buf.len = data_len;
2994
3078
  }
2995
3079
 
2996
- needed = inf->lz4_buf.len + slen;
2997
- if (needed > inf->lz4_buf.cap) {
2998
- inf->lz4_buf.cap = needed * 2;
2999
- REALLOC_N(inf->lz4_buf.buf, char, inf->lz4_buf.cap);
3000
- }
3001
3080
  memcpy(inf->lz4_buf.buf + inf->lz4_buf.len, src, slen);
3002
3081
  inf->lz4_buf.len += slen;
3003
3082
 
@@ -1,3 +1,3 @@
1
- zstd=1.5.2
1
+ zstd=1.5.7
2
2
  lz4=1.10.0
3
- brotli=1.1.0
3
+ brotli=1.2.0
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -6,10 +6,10 @@
6
6
 
7
7
  #include "constants.h"
8
8
 
9
- const BrotliPrefixCodeRange
10
- _kBrotliPrefixCodeRanges[BROTLI_NUM_BLOCK_LEN_SYMBOLS] = {
11
- {1, 2}, {5, 2}, {9, 2}, {13, 2}, {17, 3}, {25, 3},
12
- {33, 3}, {41, 3}, {49, 4}, {65, 4}, {81, 4}, {97, 4},
13
- {113, 5}, {145, 5}, {177, 5}, {209, 5}, {241, 6}, {305, 6},
14
- {369, 7}, {497, 8}, {753, 9}, {1265, 10}, {2289, 11}, {4337, 12},
15
- {8433, 13}, {16625, 24}};
9
+ const BROTLI_MODEL("small")
10
+ BrotliPrefixCodeRange _kBrotliPrefixCodeRanges[BROTLI_NUM_BLOCK_LEN_SYMBOLS] = {
11
+ {1, 2}, {5, 2}, {9, 2}, {13, 2}, {17, 3}, {25, 3},
12
+ {33, 3}, {41, 3}, {49, 4}, {65, 4}, {81, 4}, {97, 4},
13
+ {113, 5}, {145, 5}, {177, 5}, {209, 5}, {241, 6}, {305, 6},
14
+ {369, 7}, {497, 8}, {753, 9}, {1265, 10}, {2289, 11}, {4337, 12},
15
+ {8433, 13}, {16625, 24}};
@@ -12,9 +12,6 @@
12
12
  #ifndef BROTLI_COMMON_CONSTANTS_H_
13
13
  #define BROTLI_COMMON_CONSTANTS_H_
14
14
 
15
- #include <brotli/port.h>
16
- #include <brotli/types.h>
17
-
18
15
  #include "platform.h"
19
16
 
20
17
  /* Specification: 7.3. Encoding of the context map */
@@ -195,7 +192,7 @@ typedef struct {
195
192
  } BrotliPrefixCodeRange;
196
193
 
197
194
  /* "Soft-private", it is exported, but not "advertised" as API. */
198
- BROTLI_COMMON_API extern const BrotliPrefixCodeRange
199
- _kBrotliPrefixCodeRanges[BROTLI_NUM_BLOCK_LEN_SYMBOLS];
195
+ BROTLI_COMMON_API extern const BROTLI_MODEL("small")
196
+ BrotliPrefixCodeRange _kBrotliPrefixCodeRanges[BROTLI_NUM_BLOCK_LEN_SYMBOLS];
200
197
 
201
198
  #endif /* BROTLI_COMMON_CONSTANTS_H_ */
@@ -1,9 +1,9 @@
1
1
  #include "context.h"
2
2
 
3
- #include <brotli/types.h>
3
+ #include "platform.h"
4
4
 
5
5
  /* Common context lookup table for all context modes. */
6
- const uint8_t _kBrotliContextLookupTable[2048] = {
6
+ const BROTLI_MODEL("small") uint8_t _kBrotliContextLookupTable[2048] = {
7
7
  /* CONTEXT_LSB6, last byte. */
8
8
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
9
9
  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
@@ -88,8 +88,7 @@
88
88
  #ifndef BROTLI_COMMON_CONTEXT_H_
89
89
  #define BROTLI_COMMON_CONTEXT_H_
90
90
 
91
- #include <brotli/port.h>
92
- #include <brotli/types.h>
91
+ #include "platform.h"
93
92
 
94
93
  typedef enum ContextType {
95
94
  CONTEXT_LSB6 = 0,