brotli 0.2.3 → 0.5.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.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +37 -0
- data/.github/workflows/publish.yml +24 -0
- data/.gitmodules +1 -1
- data/Gemfile +6 -3
- data/README.md +2 -2
- data/Rakefile +16 -9
- data/brotli.gemspec +7 -13
- data/ext/brotli/brotli.c +210 -31
- data/ext/brotli/buffer.c +1 -7
- data/ext/brotli/buffer.h +1 -1
- data/ext/brotli/extconf.rb +25 -17
- data/lib/brotli/version.rb +1 -1
- data/test/brotli_test.rb +107 -0
- data/test/brotli_writer_test.rb +36 -0
- data/test/test_helper.rb +8 -0
- data/vendor/brotli/c/common/constants.c +15 -0
- data/vendor/brotli/c/common/constants.h +137 -0
- data/vendor/brotli/c/common/context.c +156 -0
- data/vendor/brotli/c/common/context.h +4 -152
- data/vendor/brotli/c/common/dictionary.bin.br +0 -0
- data/vendor/brotli/c/common/dictionary.c +14 -3
- data/vendor/brotli/c/common/platform.c +23 -0
- data/vendor/brotli/c/common/platform.h +95 -122
- data/vendor/brotli/c/common/shared_dictionary.c +521 -0
- data/vendor/brotli/c/common/shared_dictionary_internal.h +75 -0
- data/vendor/brotli/c/common/transform.c +60 -4
- data/vendor/brotli/c/common/transform.h +5 -0
- data/vendor/brotli/c/common/version.h +31 -6
- data/vendor/brotli/c/dec/bit_reader.c +34 -4
- data/vendor/brotli/c/dec/bit_reader.h +221 -107
- data/vendor/brotli/c/dec/decode.c +772 -403
- data/vendor/brotli/c/dec/huffman.c +7 -4
- data/vendor/brotli/c/dec/huffman.h +8 -13
- data/vendor/brotli/c/dec/prefix.h +1 -18
- data/vendor/brotli/c/dec/state.c +40 -21
- data/vendor/brotli/c/dec/state.h +201 -59
- data/vendor/brotli/c/enc/backward_references.c +88 -25
- data/vendor/brotli/c/enc/backward_references.h +10 -8
- data/vendor/brotli/c/enc/backward_references_hq.c +194 -80
- data/vendor/brotli/c/enc/backward_references_hq.h +17 -13
- data/vendor/brotli/c/enc/backward_references_inc.h +52 -16
- data/vendor/brotli/c/enc/bit_cost.c +8 -7
- data/vendor/brotli/c/enc/bit_cost.h +5 -4
- data/vendor/brotli/c/enc/block_splitter.c +40 -17
- data/vendor/brotli/c/enc/block_splitter.h +5 -4
- data/vendor/brotli/c/enc/block_splitter_inc.h +99 -49
- data/vendor/brotli/c/enc/brotli_bit_stream.c +142 -137
- data/vendor/brotli/c/enc/brotli_bit_stream.h +11 -6
- data/vendor/brotli/c/enc/cluster.c +10 -9
- data/vendor/brotli/c/enc/cluster.h +7 -6
- data/vendor/brotli/c/enc/cluster_inc.h +30 -22
- data/vendor/brotli/c/enc/command.c +28 -0
- data/vendor/brotli/c/enc/command.h +17 -16
- data/vendor/brotli/c/enc/compound_dictionary.c +207 -0
- data/vendor/brotli/c/enc/compound_dictionary.h +74 -0
- data/vendor/brotli/c/enc/compress_fragment.c +93 -83
- data/vendor/brotli/c/enc/compress_fragment.h +32 -7
- data/vendor/brotli/c/enc/compress_fragment_two_pass.c +100 -88
- data/vendor/brotli/c/enc/compress_fragment_two_pass.h +21 -3
- data/vendor/brotli/c/enc/dictionary_hash.c +1829 -1101
- data/vendor/brotli/c/enc/dictionary_hash.h +2 -1
- data/vendor/brotli/c/enc/encode.c +550 -416
- data/vendor/brotli/c/enc/encoder_dict.c +613 -5
- data/vendor/brotli/c/enc/encoder_dict.h +120 -4
- data/vendor/brotli/c/enc/entropy_encode.c +5 -2
- data/vendor/brotli/c/enc/entropy_encode.h +4 -3
- data/vendor/brotli/c/enc/entropy_encode_static.h +5 -2
- data/vendor/brotli/c/enc/fast_log.c +105 -0
- data/vendor/brotli/c/enc/fast_log.h +21 -101
- data/vendor/brotli/c/enc/find_match_length.h +17 -25
- data/vendor/brotli/c/enc/hash.h +350 -120
- data/vendor/brotli/c/enc/hash_composite_inc.h +71 -67
- data/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +92 -51
- data/vendor/brotli/c/enc/hash_longest_match64_inc.h +79 -84
- data/vendor/brotli/c/enc/hash_longest_match_inc.h +53 -54
- data/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +93 -62
- data/vendor/brotli/c/enc/hash_rolling_inc.h +25 -29
- data/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +42 -40
- data/vendor/brotli/c/enc/histogram.c +4 -4
- data/vendor/brotli/c/enc/histogram.h +7 -6
- data/vendor/brotli/c/enc/literal_cost.c +20 -15
- data/vendor/brotli/c/enc/literal_cost.h +4 -2
- data/vendor/brotli/c/enc/memory.c +29 -5
- data/vendor/brotli/c/enc/memory.h +43 -14
- data/vendor/brotli/c/enc/metablock.c +95 -85
- data/vendor/brotli/c/enc/metablock.h +9 -8
- data/vendor/brotli/c/enc/metablock_inc.h +9 -7
- data/vendor/brotli/c/enc/params.h +7 -4
- data/vendor/brotli/c/enc/prefix.h +3 -2
- data/vendor/brotli/c/enc/quality.h +40 -3
- data/vendor/brotli/c/enc/ringbuffer.h +8 -4
- data/vendor/brotli/c/enc/state.h +104 -0
- data/vendor/brotli/c/enc/static_dict.c +60 -4
- data/vendor/brotli/c/enc/static_dict.h +3 -2
- data/vendor/brotli/c/enc/static_dict_lut.h +2 -0
- data/vendor/brotli/c/enc/utf8_util.c +2 -2
- data/vendor/brotli/c/enc/utf8_util.h +2 -1
- data/vendor/brotli/c/enc/write_bits.h +29 -26
- data/vendor/brotli/c/include/brotli/decode.h +67 -2
- data/vendor/brotli/c/include/brotli/encode.h +77 -3
- data/vendor/brotli/c/include/brotli/port.h +34 -3
- data/vendor/brotli/c/include/brotli/shared_dictionary.h +100 -0
- metadata +23 -97
- data/.travis.yml +0 -31
- data/docs/Brotli/Error.html +0 -124
- data/docs/Brotli.html +0 -485
- data/docs/_index.html +0 -122
- data/docs/class_list.html +0 -51
- data/docs/css/common.css +0 -1
- data/docs/css/full_list.css +0 -58
- data/docs/css/style.css +0 -496
- data/docs/file.README.html +0 -127
- data/docs/file_list.html +0 -56
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -127
- data/docs/js/app.js +0 -292
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -67
- data/docs/top-level-namespace.html +0 -110
- data/spec/brotli_spec.rb +0 -88
- data/spec/inflate_spec.rb +0 -75
- data/spec/spec_helper.rb +0 -4
@@ -11,12 +11,13 @@
|
|
11
11
|
|
12
12
|
#include <string.h> /* memset */
|
13
13
|
|
14
|
+
#include <brotli/types.h>
|
15
|
+
|
14
16
|
#include "../common/constants.h"
|
15
17
|
#include "../common/context.h"
|
16
18
|
#include "../common/platform.h"
|
17
|
-
#include
|
18
|
-
#include "
|
19
|
-
#include "./command.h"
|
19
|
+
#include "block_splitter.h"
|
20
|
+
#include "command.h"
|
20
21
|
|
21
22
|
#if defined(__cplusplus) || defined(c_plusplus)
|
22
23
|
extern "C" {
|
@@ -28,7 +29,7 @@ extern "C" {
|
|
28
29
|
#define FN(X) X ## Literal
|
29
30
|
#define DATA_SIZE BROTLI_NUM_LITERAL_SYMBOLS
|
30
31
|
#define DataType uint8_t
|
31
|
-
#include "
|
32
|
+
#include "histogram_inc.h" /* NOLINT(build/include) */
|
32
33
|
#undef DataType
|
33
34
|
#undef DATA_SIZE
|
34
35
|
#undef FN
|
@@ -36,13 +37,13 @@ extern "C" {
|
|
36
37
|
#define FN(X) X ## Command
|
37
38
|
#define DataType uint16_t
|
38
39
|
#define DATA_SIZE BROTLI_NUM_COMMAND_SYMBOLS
|
39
|
-
#include "
|
40
|
+
#include "histogram_inc.h" /* NOLINT(build/include) */
|
40
41
|
#undef DATA_SIZE
|
41
42
|
#undef FN
|
42
43
|
|
43
44
|
#define FN(X) X ## Distance
|
44
45
|
#define DATA_SIZE BROTLI_NUM_HISTOGRAM_DISTANCE_SYMBOLS
|
45
|
-
#include "
|
46
|
+
#include "histogram_inc.h" /* NOLINT(build/include) */
|
46
47
|
#undef DataType
|
47
48
|
#undef DATA_SIZE
|
48
49
|
#undef FN
|
@@ -7,12 +7,15 @@
|
|
7
7
|
/* Literal cost model to allow backward reference replacement to be efficient.
|
8
8
|
*/
|
9
9
|
|
10
|
-
#include "
|
10
|
+
#include "literal_cost.h"
|
11
|
+
|
12
|
+
#include <string.h> /* memset */
|
11
13
|
|
12
|
-
#include "../common/platform.h"
|
13
14
|
#include <brotli/types.h>
|
14
|
-
|
15
|
-
#include "
|
15
|
+
|
16
|
+
#include "../common/platform.h"
|
17
|
+
#include "fast_log.h"
|
18
|
+
#include "utf8_util.h"
|
16
19
|
|
17
20
|
#if defined(__cplusplus) || defined(c_plusplus)
|
18
21
|
extern "C" {
|
@@ -54,22 +57,23 @@ static size_t DecideMultiByteStatsLevel(size_t pos, size_t len, size_t mask,
|
|
54
57
|
}
|
55
58
|
|
56
59
|
static void EstimateBitCostsForLiteralsUTF8(size_t pos, size_t len, size_t mask,
|
57
|
-
const uint8_t* data,
|
60
|
+
const uint8_t* data,
|
61
|
+
size_t* histogram, float* cost) {
|
58
62
|
/* max_utf8 is 0 (normal ASCII single byte modeling),
|
59
63
|
1 (for 2-byte UTF-8 modeling), or 2 (for 3-byte UTF-8 modeling). */
|
60
64
|
const size_t max_utf8 = DecideMultiByteStatsLevel(pos, len, mask, data);
|
61
|
-
size_t histogram[3][256] = { { 0 } };
|
62
65
|
size_t window_half = 495;
|
63
66
|
size_t in_window = BROTLI_MIN(size_t, window_half, len);
|
64
67
|
size_t in_window_utf8[3] = { 0 };
|
65
|
-
|
66
68
|
size_t i;
|
69
|
+
memset(histogram, 0, 3 * 256 * sizeof(histogram[0]));
|
70
|
+
|
67
71
|
{ /* Bootstrap histograms. */
|
68
72
|
size_t last_c = 0;
|
69
73
|
size_t utf8_pos = 0;
|
70
74
|
for (i = 0; i < in_window; ++i) {
|
71
75
|
size_t c = data[(pos + i) & mask];
|
72
|
-
++histogram[utf8_pos
|
76
|
+
++histogram[256 * utf8_pos + c];
|
73
77
|
++in_window_utf8[utf8_pos];
|
74
78
|
utf8_pos = UTF8Position(last_c, c, max_utf8);
|
75
79
|
last_c = c;
|
@@ -85,7 +89,7 @@ static void EstimateBitCostsForLiteralsUTF8(size_t pos, size_t len, size_t mask,
|
|
85
89
|
size_t last_c =
|
86
90
|
i < window_half + 2 ? 0 : data[(pos + i - window_half - 2) & mask];
|
87
91
|
size_t utf8_pos2 = UTF8Position(last_c, c, max_utf8);
|
88
|
-
--histogram[utf8_pos2
|
92
|
+
--histogram[256 * utf8_pos2 + data[(pos + i - window_half) & mask]];
|
89
93
|
--in_window_utf8[utf8_pos2];
|
90
94
|
}
|
91
95
|
if (i + window_half < len) {
|
@@ -93,7 +97,7 @@ static void EstimateBitCostsForLiteralsUTF8(size_t pos, size_t len, size_t mask,
|
|
93
97
|
size_t c = data[(pos + i + window_half - 1) & mask];
|
94
98
|
size_t last_c = data[(pos + i + window_half - 2) & mask];
|
95
99
|
size_t utf8_pos2 = UTF8Position(last_c, c, max_utf8);
|
96
|
-
++histogram[utf8_pos2
|
100
|
+
++histogram[256 * utf8_pos2 + data[(pos + i + window_half) & mask]];
|
97
101
|
++in_window_utf8[utf8_pos2];
|
98
102
|
}
|
99
103
|
{
|
@@ -101,7 +105,7 @@ static void EstimateBitCostsForLiteralsUTF8(size_t pos, size_t len, size_t mask,
|
|
101
105
|
size_t last_c = i < 2 ? 0 : data[(pos + i - 2) & mask];
|
102
106
|
size_t utf8_pos = UTF8Position(last_c, c, max_utf8);
|
103
107
|
size_t masked_pos = (pos + i) & mask;
|
104
|
-
size_t histo = histogram[utf8_pos
|
108
|
+
size_t histo = histogram[256 * utf8_pos + data[masked_pos]];
|
105
109
|
double lit_cost;
|
106
110
|
if (histo == 0) {
|
107
111
|
histo = 1;
|
@@ -125,17 +129,18 @@ static void EstimateBitCostsForLiteralsUTF8(size_t pos, size_t len, size_t mask,
|
|
125
129
|
}
|
126
130
|
|
127
131
|
void BrotliEstimateBitCostsForLiterals(size_t pos, size_t len, size_t mask,
|
128
|
-
const uint8_t* data,
|
132
|
+
const uint8_t* data,
|
133
|
+
size_t* histogram, float* cost) {
|
129
134
|
if (BrotliIsMostlyUTF8(data, pos, mask, len, kMinUTF8Ratio)) {
|
130
|
-
EstimateBitCostsForLiteralsUTF8(pos, len, mask, data, cost);
|
135
|
+
EstimateBitCostsForLiteralsUTF8(pos, len, mask, data, histogram, cost);
|
131
136
|
return;
|
132
137
|
} else {
|
133
|
-
size_t histogram[256] = { 0 };
|
134
138
|
size_t window_half = 2000;
|
135
139
|
size_t in_window = BROTLI_MIN(size_t, window_half, len);
|
140
|
+
size_t i;
|
141
|
+
memset(histogram, 0, 256 * sizeof(histogram[0]));
|
136
142
|
|
137
143
|
/* Bootstrap histogram. */
|
138
|
-
size_t i;
|
139
144
|
for (i = 0; i < in_window; ++i) {
|
140
145
|
++histogram[data[(pos + i) & mask]];
|
141
146
|
}
|
@@ -10,9 +10,10 @@
|
|
10
10
|
#ifndef BROTLI_ENC_LITERAL_COST_H_
|
11
11
|
#define BROTLI_ENC_LITERAL_COST_H_
|
12
12
|
|
13
|
-
#include "../common/platform.h"
|
14
13
|
#include <brotli/types.h>
|
15
14
|
|
15
|
+
#include "../common/platform.h"
|
16
|
+
|
16
17
|
#if defined(__cplusplus) || defined(c_plusplus)
|
17
18
|
extern "C" {
|
18
19
|
#endif
|
@@ -21,7 +22,8 @@ extern "C" {
|
|
21
22
|
ring-buffer (data, mask) will take entropy coded and writes these estimates
|
22
23
|
to the cost[0..len) array. */
|
23
24
|
BROTLI_INTERNAL void BrotliEstimateBitCostsForLiterals(
|
24
|
-
size_t pos, size_t len, size_t mask, const uint8_t* data,
|
25
|
+
size_t pos, size_t len, size_t mask, const uint8_t* data, size_t* histogram,
|
26
|
+
float* cost);
|
25
27
|
|
26
28
|
#if defined(__cplusplus) || defined(c_plusplus)
|
27
29
|
} /* extern "C" */
|
@@ -7,21 +7,22 @@
|
|
7
7
|
/* Algorithms for distributing the literals and commands of a metablock between
|
8
8
|
block types and contexts. */
|
9
9
|
|
10
|
-
#include "
|
10
|
+
#include "memory.h"
|
11
11
|
|
12
12
|
#include <stdlib.h> /* exit, free, malloc */
|
13
13
|
#include <string.h> /* memcpy */
|
14
14
|
|
15
|
-
#include "../common/platform.h"
|
16
15
|
#include <brotli/types.h>
|
17
16
|
|
17
|
+
#include "../common/platform.h"
|
18
|
+
|
18
19
|
#if defined(__cplusplus) || defined(c_plusplus)
|
19
20
|
extern "C" {
|
20
21
|
#endif
|
21
22
|
|
22
|
-
#define
|
23
|
-
#define
|
24
|
-
#define
|
23
|
+
#define MAX_NEW_ALLOCATED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 2)
|
24
|
+
#define MAX_NEW_FREED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 2)
|
25
|
+
#define MAX_PERM_ALLOCATED (BROTLI_ENCODER_MEMORY_MANAGER_SLOTS >> 1)
|
25
26
|
|
26
27
|
#define PERM_ALLOCATED_OFFSET 0
|
27
28
|
#define NEW_ALLOCATED_OFFSET MAX_PERM_ALLOCATED
|
@@ -67,6 +68,7 @@ void BrotliWipeOutMemoryManager(MemoryManager* m) {
|
|
67
68
|
|
68
69
|
static void SortPointers(void** items, const size_t n) {
|
69
70
|
/* Shell sort. */
|
71
|
+
/* TODO(eustas): fine-tune for "many slots" case */
|
70
72
|
static const size_t gaps[] = {23, 10, 4, 1};
|
71
73
|
int g = 0;
|
72
74
|
for (; g < 4; ++g) {
|
@@ -165,6 +167,28 @@ void BrotliWipeOutMemoryManager(MemoryManager* m) {
|
|
165
167
|
|
166
168
|
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
|
167
169
|
|
170
|
+
void* BrotliBootstrapAlloc(size_t size,
|
171
|
+
brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {
|
172
|
+
if (!alloc_func && !free_func) {
|
173
|
+
return malloc(size);
|
174
|
+
} else if (alloc_func && free_func) {
|
175
|
+
return alloc_func(opaque, size);
|
176
|
+
}
|
177
|
+
return NULL;
|
178
|
+
}
|
179
|
+
|
180
|
+
void BrotliBootstrapFree(void* address, MemoryManager* m) {
|
181
|
+
if (!address) {
|
182
|
+
/* Should not happen! */
|
183
|
+
return;
|
184
|
+
} else {
|
185
|
+
/* Copy values, as those would be freed. */
|
186
|
+
brotli_free_func free_func = m->free_func;
|
187
|
+
void* opaque = m->opaque;
|
188
|
+
free_func(opaque, address);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
168
192
|
#if defined(__cplusplus) || defined(c_plusplus)
|
169
193
|
} /* extern "C" */
|
170
194
|
#endif
|
@@ -11,9 +11,10 @@
|
|
11
11
|
|
12
12
|
#include <string.h> /* memcpy */
|
13
13
|
|
14
|
-
#include "../common/platform.h"
|
15
14
|
#include <brotli/types.h>
|
16
15
|
|
16
|
+
#include "../common/platform.h"
|
17
|
+
|
17
18
|
#if defined(__cplusplus) || defined(c_plusplus)
|
18
19
|
extern "C" {
|
19
20
|
#endif
|
@@ -23,6 +24,16 @@ extern "C" {
|
|
23
24
|
#define BROTLI_ENCODER_EXIT_ON_OOM
|
24
25
|
#endif
|
25
26
|
|
27
|
+
#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
|
28
|
+
#if defined(BROTLI_EXPERIMENTAL)
|
29
|
+
#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS (48*1024)
|
30
|
+
#else /* BROTLI_EXPERIMENTAL */
|
31
|
+
#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 256
|
32
|
+
#endif /* BROTLI_EXPERIMENTAL */
|
33
|
+
#else /* BROTLI_ENCODER_EXIT_ON_OOM */
|
34
|
+
#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 0
|
35
|
+
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
|
36
|
+
|
26
37
|
typedef struct MemoryManager {
|
27
38
|
brotli_alloc_func alloc_func;
|
28
39
|
brotli_free_func free_func;
|
@@ -32,7 +43,7 @@ typedef struct MemoryManager {
|
|
32
43
|
size_t perm_allocated;
|
33
44
|
size_t new_allocated;
|
34
45
|
size_t new_freed;
|
35
|
-
void* pointers[
|
46
|
+
void* pointers[BROTLI_ENCODER_MEMORY_MANAGER_SLOTS];
|
36
47
|
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
|
37
48
|
} MemoryManager;
|
38
49
|
|
@@ -56,6 +67,18 @@ BROTLI_INTERNAL void BrotliFree(MemoryManager* m, void* p);
|
|
56
67
|
#define BROTLI_IS_OOM(M) (!!(M)->is_oom)
|
57
68
|
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
|
58
69
|
|
70
|
+
/*
|
71
|
+
BROTLI_IS_NULL is a fake check, BROTLI_IS_OOM does the heavy lifting.
|
72
|
+
The only purpose of it is to explain static analyzers the state of things.
|
73
|
+
NB: use ONLY together with BROTLI_IS_OOM
|
74
|
+
AND ONLY for allocations in the current scope.
|
75
|
+
*/
|
76
|
+
#if defined(__clang_analyzer__) && !defined(BROTLI_ENCODER_EXIT_ON_OOM)
|
77
|
+
#define BROTLI_IS_NULL(A) ((A) == nullptr)
|
78
|
+
#else /* defined(__clang_analyzer__) */
|
79
|
+
#define BROTLI_IS_NULL(A) (!!0)
|
80
|
+
#endif /* defined(__clang_analyzer__) */
|
81
|
+
|
59
82
|
BROTLI_INTERNAL void BrotliWipeOutMemoryManager(MemoryManager* m);
|
60
83
|
|
61
84
|
/*
|
@@ -66,18 +89,18 @@ A: array
|
|
66
89
|
C: capacity
|
67
90
|
R: requested size
|
68
91
|
*/
|
69
|
-
#define BROTLI_ENSURE_CAPACITY(M, T, A, C, R) {
|
70
|
-
if (C < (R)) {
|
71
|
-
size_t _new_size = (C == 0) ? (R) : C;
|
72
|
-
T* new_array;
|
73
|
-
while (_new_size < (R)) _new_size *= 2;
|
74
|
-
new_array = BROTLI_ALLOC((M), T, _new_size);
|
75
|
-
if (!BROTLI_IS_OOM(M) && C != 0)
|
76
|
-
memcpy(new_array, A, C * sizeof(T));
|
77
|
-
BROTLI_FREE((M), A);
|
78
|
-
A = new_array;
|
79
|
-
C = _new_size;
|
80
|
-
}
|
92
|
+
#define BROTLI_ENSURE_CAPACITY(M, T, A, C, R) { \
|
93
|
+
if (C < (R)) { \
|
94
|
+
size_t _new_size = (C == 0) ? (R) : C; \
|
95
|
+
T* new_array; \
|
96
|
+
while (_new_size < (R)) _new_size *= 2; \
|
97
|
+
new_array = BROTLI_ALLOC((M), T, _new_size); \
|
98
|
+
if (!BROTLI_IS_OOM(M) && !BROTLI_IS_NULL(new_array) && C != 0) \
|
99
|
+
memcpy(new_array, A, C * sizeof(T)); \
|
100
|
+
BROTLI_FREE((M), A); \
|
101
|
+
A = new_array; \
|
102
|
+
C = _new_size; \
|
103
|
+
} \
|
81
104
|
}
|
82
105
|
|
83
106
|
/*
|
@@ -95,6 +118,12 @@ V: value to append
|
|
95
118
|
A[(S) - 1] = (V); \
|
96
119
|
}
|
97
120
|
|
121
|
+
/* "Bootstrap" allocations are not tracked by memory manager; should be used
|
122
|
+
only to allocate MemoryManager itself (or structure containing it). */
|
123
|
+
BROTLI_INTERNAL void* BrotliBootstrapAlloc(size_t size,
|
124
|
+
brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
|
125
|
+
BROTLI_INTERNAL void BrotliBootstrapFree(void* address, MemoryManager* m);
|
126
|
+
|
98
127
|
#if defined(__cplusplus) || defined(c_plusplus)
|
99
128
|
} /* extern "C" */
|
100
129
|
#endif
|