brotli 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +11 -3
- data/Gemfile +2 -0
- data/ext/brotli/brotli.c +279 -0
- data/ext/brotli/brotli.h +2 -0
- data/ext/brotli/buffer.c +95 -0
- data/ext/brotli/buffer.h +19 -0
- data/ext/brotli/extconf.rb +21 -81
- data/lib/brotli/version.rb +1 -1
- data/vendor/brotli/dec/bit_reader.c +5 -5
- data/vendor/brotli/dec/bit_reader.h +15 -15
- data/vendor/brotli/dec/context.h +1 -1
- data/vendor/brotli/dec/decode.c +433 -348
- data/vendor/brotli/dec/decode.h +74 -48
- data/vendor/brotli/dec/huffman.c +5 -4
- data/vendor/brotli/dec/huffman.h +4 -4
- data/vendor/brotli/dec/port.h +2 -95
- data/vendor/brotli/dec/prefix.h +5 -3
- data/vendor/brotli/dec/state.c +15 -27
- data/vendor/brotli/dec/state.h +21 -17
- data/vendor/brotli/dec/transform.h +1 -1
- data/vendor/brotli/enc/backward_references.c +892 -0
- data/vendor/brotli/enc/backward_references.h +85 -102
- data/vendor/brotli/enc/backward_references_inc.h +147 -0
- data/vendor/brotli/enc/bit_cost.c +35 -0
- data/vendor/brotli/enc/bit_cost.h +23 -121
- data/vendor/brotli/enc/bit_cost_inc.h +127 -0
- data/vendor/brotli/enc/block_encoder_inc.h +33 -0
- data/vendor/brotli/enc/block_splitter.c +197 -0
- data/vendor/brotli/enc/block_splitter.h +40 -50
- data/vendor/brotli/enc/block_splitter_inc.h +432 -0
- data/vendor/brotli/enc/brotli_bit_stream.c +1334 -0
- data/vendor/brotli/enc/brotli_bit_stream.h +95 -167
- data/vendor/brotli/enc/cluster.c +56 -0
- data/vendor/brotli/enc/cluster.h +23 -305
- data/vendor/brotli/enc/cluster_inc.h +315 -0
- data/vendor/brotli/enc/command.h +83 -76
- data/vendor/brotli/enc/compress_fragment.c +747 -0
- data/vendor/brotli/enc/compress_fragment.h +48 -37
- data/vendor/brotli/enc/compress_fragment_two_pass.c +557 -0
- data/vendor/brotli/enc/compress_fragment_two_pass.h +37 -26
- data/vendor/brotli/enc/compressor.cc +139 -0
- data/vendor/brotli/enc/compressor.h +146 -0
- data/vendor/brotli/enc/context.h +102 -96
- data/vendor/brotli/enc/dictionary_hash.h +9 -5
- data/vendor/brotli/enc/encode.c +1562 -0
- data/vendor/brotli/enc/encode.h +211 -199
- data/vendor/brotli/enc/encode_parallel.cc +161 -151
- data/vendor/brotli/enc/encode_parallel.h +7 -8
- data/vendor/brotli/enc/entropy_encode.c +501 -0
- data/vendor/brotli/enc/entropy_encode.h +107 -89
- data/vendor/brotli/enc/entropy_encode_static.h +29 -62
- data/vendor/brotli/enc/fast_log.h +26 -20
- data/vendor/brotli/enc/find_match_length.h +23 -20
- data/vendor/brotli/enc/hash.h +614 -871
- data/vendor/brotli/enc/hash_forgetful_chain_inc.h +249 -0
- data/vendor/brotli/enc/hash_longest_match_inc.h +241 -0
- data/vendor/brotli/enc/hash_longest_match_quickly_inc.h +230 -0
- data/vendor/brotli/enc/histogram.c +95 -0
- data/vendor/brotli/enc/histogram.h +49 -83
- data/vendor/brotli/enc/histogram_inc.h +51 -0
- data/vendor/brotli/enc/literal_cost.c +178 -0
- data/vendor/brotli/enc/literal_cost.h +16 -10
- data/vendor/brotli/enc/memory.c +181 -0
- data/vendor/brotli/enc/memory.h +62 -0
- data/vendor/brotli/enc/metablock.c +515 -0
- data/vendor/brotli/enc/metablock.h +87 -57
- data/vendor/brotli/enc/metablock_inc.h +183 -0
- data/vendor/brotli/enc/port.h +73 -47
- data/vendor/brotli/enc/prefix.h +34 -61
- data/vendor/brotli/enc/quality.h +130 -0
- data/vendor/brotli/enc/ringbuffer.h +137 -122
- data/vendor/brotli/enc/{static_dict.cc → static_dict.c} +162 -139
- data/vendor/brotli/enc/static_dict.h +23 -18
- data/vendor/brotli/enc/static_dict_lut.h +11223 -12037
- data/vendor/brotli/enc/streams.cc +7 -7
- data/vendor/brotli/enc/streams.h +32 -32
- data/vendor/brotli/enc/{utf8_util.cc → utf8_util.c} +22 -20
- data/vendor/brotli/enc/utf8_util.h +16 -9
- data/vendor/brotli/enc/write_bits.h +49 -43
- metadata +34 -25
- data/ext/brotli/brotli.cc +0 -181
- data/vendor/brotli/dec/Makefile +0 -12
- data/vendor/brotli/dec/dictionary.c +0 -9466
- data/vendor/brotli/dec/dictionary.h +0 -38
- data/vendor/brotli/dec/types.h +0 -38
- data/vendor/brotli/enc/Makefile +0 -14
- data/vendor/brotli/enc/backward_references.cc +0 -858
- data/vendor/brotli/enc/block_splitter.cc +0 -505
- data/vendor/brotli/enc/brotli_bit_stream.cc +0 -1181
- data/vendor/brotli/enc/compress_fragment.cc +0 -701
- data/vendor/brotli/enc/compress_fragment_two_pass.cc +0 -524
- data/vendor/brotli/enc/dictionary.cc +0 -9466
- data/vendor/brotli/enc/dictionary.h +0 -41
- data/vendor/brotli/enc/encode.cc +0 -1180
- data/vendor/brotli/enc/entropy_encode.cc +0 -480
- data/vendor/brotli/enc/histogram.cc +0 -67
- data/vendor/brotli/enc/literal_cost.cc +0 -165
- data/vendor/brotli/enc/metablock.cc +0 -539
- data/vendor/brotli/enc/transform.h +0 -248
- data/vendor/brotli/enc/types.h +0 -29
data/vendor/brotli/enc/command.h
CHANGED
@@ -4,16 +4,19 @@
|
|
4
4
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
|
7
|
+
/* This class models a sequence of literals and a backward reference copy. */
|
8
8
|
|
9
9
|
#ifndef BROTLI_ENC_COMMAND_H_
|
10
10
|
#define BROTLI_ENC_COMMAND_H_
|
11
11
|
|
12
|
+
#include "../common/types.h"
|
13
|
+
#include "../common/port.h"
|
12
14
|
#include "./fast_log.h"
|
13
15
|
#include "./prefix.h"
|
14
|
-
#include "./types.h"
|
15
16
|
|
16
|
-
|
17
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
18
|
+
extern "C" {
|
19
|
+
#endif
|
17
20
|
|
18
21
|
static uint32_t kInsBase[] = { 0, 1, 2, 3, 4, 5, 6, 8, 10, 14, 18, 26, 34, 50,
|
19
22
|
66, 98, 130, 194, 322, 578, 1090, 2114, 6210, 22594 };
|
@@ -24,15 +27,14 @@ static uint32_t kCopyBase[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 18, 22, 30,
|
|
24
27
|
static uint32_t kCopyExtra[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
|
25
28
|
4, 4, 5, 5, 6, 7, 8, 9, 10, 24 };
|
26
29
|
|
27
|
-
static
|
30
|
+
static BROTLI_INLINE uint16_t GetInsertLengthCode(size_t insertlen) {
|
28
31
|
if (insertlen < 6) {
|
29
|
-
return
|
32
|
+
return (uint16_t)insertlen;
|
30
33
|
} else if (insertlen < 130) {
|
31
|
-
insertlen
|
32
|
-
|
33
|
-
return static_cast<uint16_t>((nbits << 1) + (insertlen >> nbits) + 2);
|
34
|
+
uint32_t nbits = Log2FloorNonZero(insertlen - 2) - 1u;
|
35
|
+
return (uint16_t)((nbits << 1) + ((insertlen - 2) >> nbits) + 2);
|
34
36
|
} else if (insertlen < 2114) {
|
35
|
-
return
|
37
|
+
return (uint16_t)(Log2FloorNonZero(insertlen - 66) + 10);
|
36
38
|
} else if (insertlen < 6210) {
|
37
39
|
return 21u;
|
38
40
|
} else if (insertlen < 22594) {
|
@@ -42,115 +44,120 @@ static inline uint16_t GetInsertLengthCode(size_t insertlen) {
|
|
42
44
|
}
|
43
45
|
}
|
44
46
|
|
45
|
-
static
|
47
|
+
static BROTLI_INLINE uint16_t GetCopyLengthCode(size_t copylen) {
|
46
48
|
if (copylen < 10) {
|
47
|
-
return
|
49
|
+
return (uint16_t)(copylen - 2);
|
48
50
|
} else if (copylen < 134) {
|
49
|
-
copylen
|
50
|
-
|
51
|
-
return static_cast<uint16_t>((nbits << 1) + (copylen >> nbits) + 4);
|
51
|
+
uint32_t nbits = Log2FloorNonZero(copylen - 6) - 1u;
|
52
|
+
return (uint16_t)((nbits << 1) + ((copylen - 6) >> nbits) + 4);
|
52
53
|
} else if (copylen < 2118) {
|
53
|
-
return
|
54
|
+
return (uint16_t)(Log2FloorNonZero(copylen - 70) + 12);
|
54
55
|
} else {
|
55
56
|
return 23u;
|
56
57
|
}
|
57
58
|
}
|
58
59
|
|
59
|
-
static
|
60
|
-
uint16_t inscode, uint16_t copycode,
|
60
|
+
static BROTLI_INLINE uint16_t CombineLengthCodes(
|
61
|
+
uint16_t inscode, uint16_t copycode, BROTLI_BOOL use_last_distance) {
|
61
62
|
uint16_t bits64 =
|
62
|
-
|
63
|
+
(uint16_t)((copycode & 0x7u) | ((inscode & 0x7u) << 3));
|
63
64
|
if (use_last_distance && inscode < 8 && copycode < 16) {
|
64
65
|
return (copycode < 8) ? bits64 : (bits64 | 64);
|
65
66
|
} else {
|
66
|
-
|
67
|
-
|
67
|
+
/* "To convert an insert-and-copy length code to an insert length code and
|
68
|
+
a copy length code, the following table can be used" */
|
68
69
|
static const uint16_t cells[9] = { 128u, 192u, 384u, 256u, 320u, 512u,
|
69
70
|
448u, 576u, 640u };
|
70
71
|
return cells[(copycode >> 3) + 3 * (inscode >> 3)] | bits64;
|
71
72
|
}
|
72
73
|
}
|
73
74
|
|
74
|
-
static
|
75
|
-
|
76
|
-
|
75
|
+
static BROTLI_INLINE void GetLengthCode(size_t insertlen, size_t copylen,
|
76
|
+
BROTLI_BOOL use_last_distance,
|
77
|
+
uint16_t* code) {
|
77
78
|
uint16_t inscode = GetInsertLengthCode(insertlen);
|
78
79
|
uint16_t copycode = GetCopyLengthCode(copylen);
|
79
80
|
*code = CombineLengthCodes(inscode, copycode, use_last_distance);
|
80
81
|
}
|
81
82
|
|
82
|
-
static
|
83
|
+
static BROTLI_INLINE uint32_t GetInsertBase(uint16_t inscode) {
|
83
84
|
return kInsBase[inscode];
|
84
85
|
}
|
85
86
|
|
86
|
-
static
|
87
|
+
static BROTLI_INLINE uint32_t GetInsertExtra(uint16_t inscode) {
|
87
88
|
return kInsExtra[inscode];
|
88
89
|
}
|
89
90
|
|
90
|
-
static
|
91
|
+
static BROTLI_INLINE uint32_t GetCopyBase(uint16_t copycode) {
|
91
92
|
return kCopyBase[copycode];
|
92
93
|
}
|
93
94
|
|
94
|
-
static
|
95
|
+
static BROTLI_INLINE uint32_t GetCopyExtra(uint16_t copycode) {
|
95
96
|
return kCopyExtra[copycode];
|
96
97
|
}
|
97
98
|
|
98
|
-
struct Command {
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
99
|
+
typedef struct Command {
|
100
|
+
uint32_t insert_len_;
|
101
|
+
/* Stores copy_len in low 24 bits and copy_len XOR copy_code in high 8 bit. */
|
102
|
+
uint32_t copy_len_;
|
103
|
+
uint32_t dist_extra_;
|
104
|
+
uint16_t cmd_prefix_;
|
105
|
+
uint16_t dist_prefix_;
|
106
|
+
} Command;
|
107
|
+
|
108
|
+
/* distance_code is e.g. 0 for same-as-last short code, or 16 for offset 1. */
|
109
|
+
static BROTLI_INLINE void InitCommand(Command* self, size_t insertlen,
|
110
|
+
size_t copylen, size_t copylen_code, size_t distance_code) {
|
111
|
+
self->insert_len_ = (uint32_t)insertlen;
|
112
|
+
self->copy_len_ = (uint32_t)(copylen | ((copylen_code ^ copylen) << 24));
|
113
|
+
/* The distance prefix and extra bits are stored in this Command as if
|
114
|
+
npostfix and ndirect were 0, they are only recomputed later after the
|
115
|
+
clustering if needed. */
|
116
|
+
PrefixEncodeCopyDistance(
|
117
|
+
distance_code, 0, 0, &self->dist_prefix_, &self->dist_extra_);
|
118
|
+
GetLengthCode(
|
119
|
+
insertlen, copylen_code, TO_BROTLI_BOOL(self->dist_prefix_ == 0),
|
120
|
+
&self->cmd_prefix_);
|
121
|
+
}
|
112
122
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
123
|
+
static BROTLI_INLINE void InitInsertCommand(Command* self, size_t insertlen) {
|
124
|
+
self->insert_len_ = (uint32_t)insertlen;
|
125
|
+
self->copy_len_ = 4 << 24;
|
126
|
+
self->dist_extra_ = 0;
|
127
|
+
self->dist_prefix_ = 16;
|
128
|
+
GetLengthCode(insertlen, 4, BROTLI_FALSE, &self->cmd_prefix_);
|
129
|
+
}
|
118
130
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
uint32_t nbits = dist_extra_ >> 24;
|
124
|
-
uint32_t extra = dist_extra_ & 0xffffff;
|
125
|
-
uint32_t prefix = dist_prefix_ -
|
131
|
+
static BROTLI_INLINE uint32_t CommandDistanceCode(const Command* self) {
|
132
|
+
if (self->dist_prefix_ < 16) {
|
133
|
+
return self->dist_prefix_;
|
134
|
+
} else {
|
135
|
+
uint32_t nbits = self->dist_extra_ >> 24;
|
136
|
+
uint32_t extra = self->dist_extra_ & 0xffffff;
|
137
|
+
uint32_t prefix = self->dist_prefix_ - 12u - 2u * nbits;
|
126
138
|
return (prefix << nbits) + extra + 12;
|
127
139
|
}
|
140
|
+
}
|
128
141
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
}
|
135
|
-
return 3;
|
136
|
-
}
|
137
|
-
|
138
|
-
inline uint32_t copy_len(void) const {
|
139
|
-
return copy_len_ & 0xFFFFFF;
|
142
|
+
static BROTLI_INLINE uint32_t CommandDistanceContext(const Command* self) {
|
143
|
+
uint32_t r = self->cmd_prefix_ >> 6;
|
144
|
+
uint32_t c = self->cmd_prefix_ & 7;
|
145
|
+
if ((r == 0 || r == 2 || r == 4 || r == 7) && (c <= 2)) {
|
146
|
+
return c;
|
140
147
|
}
|
148
|
+
return 3;
|
149
|
+
}
|
141
150
|
|
142
|
-
|
143
|
-
|
144
|
-
|
151
|
+
static BROTLI_INLINE uint32_t CommandCopyLen(const Command* self) {
|
152
|
+
return self->copy_len_ & 0xFFFFFF;
|
153
|
+
}
|
145
154
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
uint32_t dist_extra_;
|
150
|
-
uint16_t cmd_prefix_;
|
151
|
-
uint16_t dist_prefix_;
|
152
|
-
};
|
155
|
+
static BROTLI_INLINE uint32_t CommandCopyLenCode(const Command* self) {
|
156
|
+
return (self->copy_len_ & 0xFFFFFF) ^ (self->copy_len_ >> 24);
|
157
|
+
}
|
153
158
|
|
154
|
-
|
159
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
160
|
+
} /* extern "C" */
|
161
|
+
#endif
|
155
162
|
|
156
|
-
#endif
|
163
|
+
#endif /* BROTLI_ENC_COMMAND_H_ */
|