brotli 0.2.0 → 0.4.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 (111) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/main.yml +34 -0
  3. data/.github/workflows/publish.yml +34 -0
  4. data/Gemfile +6 -2
  5. data/Rakefile +18 -6
  6. data/bin/before_install.sh +9 -0
  7. data/brotli.gemspec +7 -13
  8. data/ext/brotli/brotli.c +209 -11
  9. data/ext/brotli/buffer.c +1 -7
  10. data/ext/brotli/buffer.h +1 -1
  11. data/ext/brotli/extconf.rb +45 -26
  12. data/lib/brotli/version.rb +1 -1
  13. data/smoke.sh +1 -1
  14. data/test/brotli_test.rb +104 -0
  15. data/test/brotli_writer_test.rb +36 -0
  16. data/test/test_helper.rb +8 -0
  17. data/vendor/brotli/c/common/constants.c +15 -0
  18. data/vendor/brotli/c/common/constants.h +149 -6
  19. data/vendor/brotli/c/{dec/context.h → common/context.c} +91 -186
  20. data/vendor/brotli/c/common/context.h +113 -0
  21. data/vendor/brotli/c/common/dictionary.bin +0 -0
  22. data/vendor/brotli/c/common/dictionary.bin.br +0 -0
  23. data/vendor/brotli/c/common/dictionary.c +11 -2
  24. data/vendor/brotli/c/common/dictionary.h +4 -4
  25. data/vendor/brotli/c/common/platform.c +22 -0
  26. data/vendor/brotli/c/common/platform.h +594 -0
  27. data/vendor/brotli/c/common/transform.c +291 -0
  28. data/vendor/brotli/c/common/transform.h +85 -0
  29. data/vendor/brotli/c/common/version.h +8 -1
  30. data/vendor/brotli/c/dec/bit_reader.c +29 -1
  31. data/vendor/brotli/c/dec/bit_reader.h +91 -100
  32. data/vendor/brotli/c/dec/decode.c +665 -437
  33. data/vendor/brotli/c/dec/huffman.c +65 -84
  34. data/vendor/brotli/c/dec/huffman.h +67 -14
  35. data/vendor/brotli/c/dec/prefix.h +1 -20
  36. data/vendor/brotli/c/dec/state.c +32 -45
  37. data/vendor/brotli/c/dec/state.h +173 -55
  38. data/vendor/brotli/c/enc/backward_references.c +27 -16
  39. data/vendor/brotli/c/enc/backward_references.h +7 -7
  40. data/vendor/brotli/c/enc/backward_references_hq.c +155 -116
  41. data/vendor/brotli/c/enc/backward_references_hq.h +22 -23
  42. data/vendor/brotli/c/enc/backward_references_inc.h +32 -22
  43. data/vendor/brotli/c/enc/bit_cost.c +1 -1
  44. data/vendor/brotli/c/enc/bit_cost.h +5 -5
  45. data/vendor/brotli/c/enc/block_encoder_inc.h +7 -6
  46. data/vendor/brotli/c/enc/block_splitter.c +5 -6
  47. data/vendor/brotli/c/enc/block_splitter.h +1 -1
  48. data/vendor/brotli/c/enc/block_splitter_inc.h +26 -17
  49. data/vendor/brotli/c/enc/brotli_bit_stream.c +107 -123
  50. data/vendor/brotli/c/enc/brotli_bit_stream.h +19 -38
  51. data/vendor/brotli/c/enc/cluster.c +1 -1
  52. data/vendor/brotli/c/enc/cluster.h +1 -1
  53. data/vendor/brotli/c/enc/cluster_inc.h +6 -3
  54. data/vendor/brotli/c/enc/command.c +28 -0
  55. data/vendor/brotli/c/enc/command.h +52 -42
  56. data/vendor/brotli/c/enc/compress_fragment.c +21 -22
  57. data/vendor/brotli/c/enc/compress_fragment.h +1 -1
  58. data/vendor/brotli/c/enc/compress_fragment_two_pass.c +102 -69
  59. data/vendor/brotli/c/enc/compress_fragment_two_pass.h +1 -1
  60. data/vendor/brotli/c/enc/dictionary_hash.c +1827 -1101
  61. data/vendor/brotli/c/enc/dictionary_hash.h +2 -1
  62. data/vendor/brotli/c/enc/encode.c +358 -195
  63. data/vendor/brotli/c/enc/encoder_dict.c +33 -0
  64. data/vendor/brotli/c/enc/encoder_dict.h +43 -0
  65. data/vendor/brotli/c/enc/entropy_encode.c +16 -14
  66. data/vendor/brotli/c/enc/entropy_encode.h +7 -7
  67. data/vendor/brotli/c/enc/entropy_encode_static.h +3 -3
  68. data/vendor/brotli/c/enc/fast_log.c +105 -0
  69. data/vendor/brotli/c/enc/fast_log.h +20 -99
  70. data/vendor/brotli/c/enc/find_match_length.h +5 -6
  71. data/vendor/brotli/c/enc/hash.h +145 -103
  72. data/vendor/brotli/c/enc/hash_composite_inc.h +125 -0
  73. data/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +93 -53
  74. data/vendor/brotli/c/enc/hash_longest_match64_inc.h +54 -53
  75. data/vendor/brotli/c/enc/hash_longest_match_inc.h +58 -54
  76. data/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +95 -63
  77. data/vendor/brotli/c/enc/hash_rolling_inc.h +212 -0
  78. data/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +46 -43
  79. data/vendor/brotli/c/enc/histogram.c +9 -6
  80. data/vendor/brotli/c/enc/histogram.h +6 -3
  81. data/vendor/brotli/c/enc/histogram_inc.h +1 -1
  82. data/vendor/brotli/c/enc/literal_cost.c +5 -5
  83. data/vendor/brotli/c/enc/literal_cost.h +2 -2
  84. data/vendor/brotli/c/enc/memory.c +5 -16
  85. data/vendor/brotli/c/enc/memory.h +52 -1
  86. data/vendor/brotli/c/enc/metablock.c +171 -36
  87. data/vendor/brotli/c/enc/metablock.h +13 -8
  88. data/vendor/brotli/c/enc/metablock_inc.h +2 -2
  89. data/vendor/brotli/c/enc/params.h +46 -0
  90. data/vendor/brotli/c/enc/prefix.h +3 -4
  91. data/vendor/brotli/c/enc/quality.h +29 -24
  92. data/vendor/brotli/c/enc/ringbuffer.h +19 -12
  93. data/vendor/brotli/c/enc/static_dict.c +49 -45
  94. data/vendor/brotli/c/enc/static_dict.h +4 -3
  95. data/vendor/brotli/c/enc/static_dict_lut.h +1 -1
  96. data/vendor/brotli/c/enc/utf8_util.c +21 -21
  97. data/vendor/brotli/c/enc/utf8_util.h +1 -1
  98. data/vendor/brotli/c/enc/write_bits.h +35 -38
  99. data/vendor/brotli/c/include/brotli/decode.h +13 -8
  100. data/vendor/brotli/c/include/brotli/encode.h +54 -8
  101. data/vendor/brotli/c/include/brotli/port.h +225 -83
  102. data/vendor/brotli/c/include/brotli/types.h +0 -7
  103. metadata +28 -87
  104. data/.travis.yml +0 -30
  105. data/spec/brotli_spec.rb +0 -88
  106. data/spec/inflate_spec.rb +0 -75
  107. data/spec/spec_helper.rb +0 -4
  108. data/vendor/brotli/c/dec/port.h +0 -168
  109. data/vendor/brotli/c/dec/transform.h +0 -300
  110. data/vendor/brotli/c/enc/context.h +0 -184
  111. data/vendor/brotli/c/enc/port.h +0 -184
@@ -1,184 +0,0 @@
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
- /* Macros for endianness, branch prediction and unaligned loads and stores. */
8
-
9
- #ifndef BROTLI_ENC_PORT_H_
10
- #define BROTLI_ENC_PORT_H_
11
-
12
- #include <assert.h>
13
- #include <string.h> /* memcpy */
14
-
15
- #include <brotli/port.h>
16
- #include <brotli/types.h>
17
-
18
- #if defined OS_LINUX || defined OS_CYGWIN
19
- #include <endian.h>
20
- #elif defined OS_FREEBSD
21
- #include <machine/endian.h>
22
- #elif defined OS_MACOSX
23
- #include <machine/endian.h>
24
- /* Let's try and follow the Linux convention */
25
- #define __BYTE_ORDER BYTE_ORDER
26
- #define __LITTLE_ENDIAN LITTLE_ENDIAN
27
- #endif
28
-
29
- /* define the macro BROTLI_LITTLE_ENDIAN
30
- using the above endian definitions from endian.h if
31
- endian.h was included */
32
- #ifdef __BYTE_ORDER
33
- #if __BYTE_ORDER == __LITTLE_ENDIAN
34
- #define BROTLI_LITTLE_ENDIAN
35
- #endif
36
-
37
- #else
38
-
39
- #if defined(__LITTLE_ENDIAN__)
40
- #define BROTLI_LITTLE_ENDIAN
41
- #endif
42
- #endif /* __BYTE_ORDER */
43
-
44
- #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
45
- #define BROTLI_LITTLE_ENDIAN
46
- #endif
47
-
48
- /* Enable little-endian optimization for x64 architecture on Windows. */
49
- #if (defined(_WIN32) || defined(_WIN64)) && defined(_M_X64)
50
- #define BROTLI_LITTLE_ENDIAN
51
- #endif
52
-
53
- /* Portable handling of unaligned loads, stores, and copies.
54
- On some platforms, like ARM, the copy functions can be more efficient
55
- then a load and a store. */
56
-
57
- #if defined(BROTLI_LITTLE_ENDIAN) && (\
58
- defined(ARCH_PIII) || defined(ARCH_ATHLON) || \
59
- defined(ARCH_K8) || defined(_ARCH_PPC))
60
-
61
- /* x86 and x86-64 can perform unaligned loads/stores directly;
62
- modern PowerPC hardware can also do unaligned integer loads and stores;
63
- but note: the FPU still sends unaligned loads and stores to a trap handler!
64
- */
65
-
66
- #define BROTLI_UNALIGNED_LOAD32(_p) (*(const uint32_t *)(_p))
67
- #define BROTLI_UNALIGNED_LOAD64LE(_p) (*(const uint64_t *)(_p))
68
-
69
- #define BROTLI_UNALIGNED_STORE64LE(_p, _val) \
70
- (*(uint64_t *)(_p) = (_val))
71
-
72
- #elif defined(BROTLI_LITTLE_ENDIAN) && defined(__arm__) && \
73
- !defined(__ARM_ARCH_5__) && \
74
- !defined(__ARM_ARCH_5T__) && \
75
- !defined(__ARM_ARCH_5TE__) && \
76
- !defined(__ARM_ARCH_5TEJ__) && \
77
- !defined(__ARM_ARCH_6__) && \
78
- !defined(__ARM_ARCH_6J__) && \
79
- !defined(__ARM_ARCH_6K__) && \
80
- !defined(__ARM_ARCH_6Z__) && \
81
- !defined(__ARM_ARCH_6ZK__) && \
82
- !defined(__ARM_ARCH_6T2__)
83
-
84
- /* ARMv7 and newer support native unaligned accesses, but only of 16-bit
85
- and 32-bit values (not 64-bit); older versions either raise a fatal signal,
86
- do an unaligned read and rotate the words around a bit, or do the reads very
87
- slowly (trip through kernel mode). */
88
-
89
- #define BROTLI_UNALIGNED_LOAD32(_p) (*(const uint32_t *)(_p))
90
-
91
- static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void *p) {
92
- uint64_t t;
93
- memcpy(&t, p, sizeof t);
94
- return t;
95
- }
96
-
97
- static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void *p, uint64_t v) {
98
- memcpy(p, &v, sizeof v);
99
- }
100
-
101
- #else
102
-
103
- /* These functions are provided for architectures that don't support */
104
- /* unaligned loads and stores. */
105
-
106
- static BROTLI_INLINE uint32_t BROTLI_UNALIGNED_LOAD32(const void *p) {
107
- uint32_t t;
108
- memcpy(&t, p, sizeof t);
109
- return t;
110
- }
111
-
112
- #if defined(BROTLI_LITTLE_ENDIAN)
113
-
114
- static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void *p) {
115
- uint64_t t;
116
- memcpy(&t, p, sizeof t);
117
- return t;
118
- }
119
-
120
- static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void *p, uint64_t v) {
121
- memcpy(p, &v, sizeof v);
122
- }
123
-
124
- #else /* BROTLI_LITTLE_ENDIAN */
125
-
126
- static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void *p) {
127
- const uint8_t* in = (const uint8_t*)p;
128
- uint64_t value = (uint64_t)(in[0]);
129
- value |= (uint64_t)(in[1]) << 8;
130
- value |= (uint64_t)(in[2]) << 16;
131
- value |= (uint64_t)(in[3]) << 24;
132
- value |= (uint64_t)(in[4]) << 32;
133
- value |= (uint64_t)(in[5]) << 40;
134
- value |= (uint64_t)(in[6]) << 48;
135
- value |= (uint64_t)(in[7]) << 56;
136
- return value;
137
- }
138
-
139
- static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void *p, uint64_t v) {
140
- uint8_t* out = (uint8_t*)p;
141
- out[0] = (uint8_t)v;
142
- out[1] = (uint8_t)(v >> 8);
143
- out[2] = (uint8_t)(v >> 16);
144
- out[3] = (uint8_t)(v >> 24);
145
- out[4] = (uint8_t)(v >> 32);
146
- out[5] = (uint8_t)(v >> 40);
147
- out[6] = (uint8_t)(v >> 48);
148
- out[7] = (uint8_t)(v >> 56);
149
- }
150
-
151
- #endif /* BROTLI_LITTLE_ENDIAN */
152
-
153
- #endif
154
-
155
- #define TEMPLATE_(T) \
156
- static BROTLI_INLINE T brotli_min_ ## T (T a, T b) { return a < b ? a : b; } \
157
- static BROTLI_INLINE T brotli_max_ ## T (T a, T b) { return a > b ? a : b; }
158
- TEMPLATE_(double) TEMPLATE_(float) TEMPLATE_(int)
159
- TEMPLATE_(size_t) TEMPLATE_(uint32_t) TEMPLATE_(uint8_t)
160
- #undef TEMPLATE_
161
- #define BROTLI_MIN(T, A, B) (brotli_min_ ## T((A), (B)))
162
- #define BROTLI_MAX(T, A, B) (brotli_max_ ## T((A), (B)))
163
-
164
- #define BROTLI_SWAP(T, A, I, J) { \
165
- T __brotli_swap_tmp = (A)[(I)]; \
166
- (A)[(I)] = (A)[(J)]; \
167
- (A)[(J)] = __brotli_swap_tmp; \
168
- }
169
-
170
- #define BROTLI_ENSURE_CAPACITY(M, T, A, C, R) { \
171
- if (C < (R)) { \
172
- size_t _new_size = (C == 0) ? (R) : C; \
173
- T* new_array; \
174
- while (_new_size < (R)) _new_size *= 2; \
175
- new_array = BROTLI_ALLOC((M), T, _new_size); \
176
- if (!BROTLI_IS_OOM(m) && C != 0) \
177
- memcpy(new_array, A, C * sizeof(T)); \
178
- BROTLI_FREE((M), A); \
179
- A = new_array; \
180
- C = _new_size; \
181
- } \
182
- }
183
-
184
- #endif /* BROTLI_ENC_PORT_H_ */