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
@@ -4,21 +4,27 @@
|
|
4
4
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
|
7
|
+
/* Literal cost model to allow backward reference replacement to be efficient.
|
8
|
+
*/
|
8
9
|
|
9
10
|
#ifndef BROTLI_ENC_LITERAL_COST_H_
|
10
11
|
#define BROTLI_ENC_LITERAL_COST_H_
|
11
12
|
|
12
|
-
#include "
|
13
|
+
#include "../common/types.h"
|
14
|
+
#include "./port.h"
|
13
15
|
|
14
|
-
|
16
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
17
|
+
extern "C" {
|
18
|
+
#endif
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
void
|
20
|
-
|
20
|
+
/* Estimates how many bits the literals in the interval [pos, pos + len) in the
|
21
|
+
ringbuffer (data, mask) will take entropy coded and writes these estimates
|
22
|
+
to the cost[0..len) array. */
|
23
|
+
BROTLI_INTERNAL void BrotliEstimateBitCostsForLiterals(
|
24
|
+
size_t pos, size_t len, size_t mask, const uint8_t *data, float *cost);
|
21
25
|
|
22
|
-
|
26
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
27
|
+
} /* extern "C" */
|
28
|
+
#endif
|
23
29
|
|
24
|
-
#endif
|
30
|
+
#endif /* BROTLI_ENC_LITERAL_COST_H_ */
|
@@ -0,0 +1,181 @@
|
|
1
|
+
/* Copyright 2015 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
|
+
/* Algorithms for distributing the literals and commands of a metablock between
|
8
|
+
block types and contexts. */
|
9
|
+
|
10
|
+
#include "./memory.h"
|
11
|
+
|
12
|
+
#include <assert.h>
|
13
|
+
#include <stdlib.h> /* exit, free, malloc */
|
14
|
+
#include <string.h> /* memcpy */
|
15
|
+
|
16
|
+
#include "../common/types.h"
|
17
|
+
#include "./port.h"
|
18
|
+
|
19
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
20
|
+
extern "C" {
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#define MAX_PERM_ALLOCATED 128
|
24
|
+
#define MAX_NEW_ALLOCATED 64
|
25
|
+
#define MAX_NEW_FREED 64
|
26
|
+
|
27
|
+
#define PERM_ALLOCATED_OFFSET 0
|
28
|
+
#define NEW_ALLOCATED_OFFSET MAX_PERM_ALLOCATED
|
29
|
+
#define NEW_FREED_OFFSET (MAX_PERM_ALLOCATED + MAX_NEW_ALLOCATED)
|
30
|
+
|
31
|
+
static void* DefaultAllocFunc(void* opaque, size_t size) {
|
32
|
+
BROTLI_UNUSED(opaque);
|
33
|
+
return malloc(size);
|
34
|
+
}
|
35
|
+
|
36
|
+
static void DefaultFreeFunc(void* opaque, void* address) {
|
37
|
+
BROTLI_UNUSED(opaque);
|
38
|
+
free(address);
|
39
|
+
}
|
40
|
+
|
41
|
+
void BrotliInitMemoryManager(
|
42
|
+
MemoryManager* m, brotli_alloc_func alloc_func, brotli_free_func free_func,
|
43
|
+
void* opaque) {
|
44
|
+
if (!alloc_func) {
|
45
|
+
m->alloc_func = DefaultAllocFunc;
|
46
|
+
m->free_func = DefaultFreeFunc;
|
47
|
+
m->opaque = 0;
|
48
|
+
} else {
|
49
|
+
m->alloc_func = alloc_func;
|
50
|
+
m->free_func = free_func;
|
51
|
+
m->opaque = opaque;
|
52
|
+
}
|
53
|
+
#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
|
54
|
+
m->is_oom = BROTLI_FALSE;
|
55
|
+
m->perm_allocated = 0;
|
56
|
+
m->new_allocated = 0;
|
57
|
+
m->new_freed = 0;
|
58
|
+
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
|
59
|
+
}
|
60
|
+
|
61
|
+
#if defined(BROTLI_ENCODER_EXIT_ON_OOM)
|
62
|
+
|
63
|
+
void* BrotliAllocate(MemoryManager* m, size_t n) {
|
64
|
+
void* result = m->alloc_func(m->opaque, n);
|
65
|
+
if (!result) exit(EXIT_FAILURE);
|
66
|
+
return result;
|
67
|
+
}
|
68
|
+
|
69
|
+
void BrotliFree(MemoryManager* m, void* p) {
|
70
|
+
m->free_func(m->opaque, p);
|
71
|
+
}
|
72
|
+
|
73
|
+
void BrotliWipeOutMemoryManager(MemoryManager* m) {
|
74
|
+
BROTLI_UNUSED(m);
|
75
|
+
}
|
76
|
+
|
77
|
+
#else /* BROTLI_ENCODER_EXIT_ON_OOM */
|
78
|
+
|
79
|
+
static void SortPointers(void** items, const size_t n) {
|
80
|
+
/* Shell sort. */
|
81
|
+
static const size_t gaps[] = {23, 10, 4, 1};
|
82
|
+
int g = 0;
|
83
|
+
for (; g < 4; ++g) {
|
84
|
+
size_t gap = gaps[g];
|
85
|
+
size_t i;
|
86
|
+
for (i = gap; i < n; ++i) {
|
87
|
+
size_t j = i;
|
88
|
+
void* tmp = items[i];
|
89
|
+
for (; j >= gap && tmp < items[j - gap]; j -= gap) {
|
90
|
+
items[j] = items[j - gap];
|
91
|
+
}
|
92
|
+
items[j] = tmp;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
static size_t Annihilate(void** a, size_t a_len, void** b, size_t b_len) {
|
98
|
+
size_t a_read_index = 0;
|
99
|
+
size_t b_read_index = 0;
|
100
|
+
size_t a_write_index = 0;
|
101
|
+
size_t b_write_index = 0;
|
102
|
+
size_t annihilated = 0;
|
103
|
+
while (a_read_index < a_len && b_read_index < b_len) {
|
104
|
+
if (a[a_read_index] == b[b_read_index]) {
|
105
|
+
a_read_index++;
|
106
|
+
b_read_index++;
|
107
|
+
annihilated++;
|
108
|
+
} else if (a[a_read_index] < b[b_read_index]) {
|
109
|
+
a[a_write_index++] = a[a_read_index++];
|
110
|
+
} else {
|
111
|
+
b[b_write_index++] = b[b_read_index++];
|
112
|
+
}
|
113
|
+
}
|
114
|
+
while (a_read_index < a_len) a[a_write_index++] = a[a_read_index++];
|
115
|
+
while (b_read_index < b_len) b[b_write_index++] = b[b_read_index++];
|
116
|
+
return annihilated;
|
117
|
+
}
|
118
|
+
|
119
|
+
static void CollectGarbagePointers(MemoryManager* m) {
|
120
|
+
size_t annihilated;
|
121
|
+
SortPointers(m->pointers + NEW_ALLOCATED_OFFSET, m->new_allocated);
|
122
|
+
SortPointers(m->pointers + NEW_FREED_OFFSET, m->new_freed);
|
123
|
+
annihilated = Annihilate(
|
124
|
+
m->pointers + NEW_ALLOCATED_OFFSET, m->new_allocated,
|
125
|
+
m->pointers + NEW_FREED_OFFSET, m->new_freed);
|
126
|
+
m->new_allocated -= annihilated;
|
127
|
+
m->new_freed -= annihilated;
|
128
|
+
|
129
|
+
if (m->new_freed != 0) {
|
130
|
+
annihilated = Annihilate(
|
131
|
+
m->pointers + PERM_ALLOCATED_OFFSET, m->perm_allocated,
|
132
|
+
m->pointers + NEW_FREED_OFFSET, m->new_freed);
|
133
|
+
m->perm_allocated -= annihilated;
|
134
|
+
m->new_freed -= annihilated;
|
135
|
+
assert(m->new_freed == 0);
|
136
|
+
}
|
137
|
+
|
138
|
+
if (m->new_allocated != 0) {
|
139
|
+
assert(m->perm_allocated + m->new_allocated <= MAX_PERM_ALLOCATED);
|
140
|
+
memcpy(m->pointers + PERM_ALLOCATED_OFFSET + m->perm_allocated,
|
141
|
+
m->pointers + NEW_ALLOCATED_OFFSET,
|
142
|
+
sizeof(void*) * m->new_allocated);
|
143
|
+
m->perm_allocated += m->new_allocated;
|
144
|
+
m->new_allocated = 0;
|
145
|
+
SortPointers(m->pointers + PERM_ALLOCATED_OFFSET, m->perm_allocated);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
void* BrotliAllocate(MemoryManager* m, size_t n) {
|
150
|
+
void* result = m->alloc_func(m->opaque, n);
|
151
|
+
if (!result) {
|
152
|
+
m->is_oom = BROTLI_TRUE;
|
153
|
+
return NULL;
|
154
|
+
}
|
155
|
+
if (m->new_allocated == MAX_NEW_ALLOCATED) CollectGarbagePointers(m);
|
156
|
+
m->pointers[NEW_ALLOCATED_OFFSET + (m->new_allocated++)] = result;
|
157
|
+
return result;
|
158
|
+
}
|
159
|
+
|
160
|
+
void BrotliFree(MemoryManager* m, void* p) {
|
161
|
+
if (!p) return;
|
162
|
+
m->free_func(m->opaque, p);
|
163
|
+
if (m->new_freed == MAX_NEW_FREED) CollectGarbagePointers(m);
|
164
|
+
m->pointers[NEW_FREED_OFFSET + (m->new_freed++)] = p;
|
165
|
+
}
|
166
|
+
|
167
|
+
void BrotliWipeOutMemoryManager(MemoryManager* m) {
|
168
|
+
size_t i;
|
169
|
+
CollectGarbagePointers(m);
|
170
|
+
/* Now all unfreed pointers are in perm-allocated list. */
|
171
|
+
for (i = 0; i < m->perm_allocated; ++i) {
|
172
|
+
m->free_func(m->opaque, m->pointers[PERM_ALLOCATED_OFFSET + i]);
|
173
|
+
}
|
174
|
+
m->perm_allocated = 0;
|
175
|
+
}
|
176
|
+
|
177
|
+
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
|
178
|
+
|
179
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
180
|
+
} /* extern "C" */
|
181
|
+
#endif
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/* Copyright 2016 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 memory management. */
|
8
|
+
|
9
|
+
#ifndef BROTLI_ENC_MEMORY_H_
|
10
|
+
#define BROTLI_ENC_MEMORY_H_
|
11
|
+
|
12
|
+
#include "../common/types.h"
|
13
|
+
#include "./port.h"
|
14
|
+
|
15
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
16
|
+
extern "C" {
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \
|
20
|
+
!defined(BROTLI_ENCODER_EXIT_ON_OOM)
|
21
|
+
#define BROTLI_ENCODER_EXIT_ON_OOM
|
22
|
+
#endif
|
23
|
+
|
24
|
+
typedef struct MemoryManager {
|
25
|
+
brotli_alloc_func alloc_func;
|
26
|
+
brotli_free_func free_func;
|
27
|
+
void* opaque;
|
28
|
+
#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
|
29
|
+
BROTLI_BOOL is_oom;
|
30
|
+
size_t perm_allocated;
|
31
|
+
size_t new_allocated;
|
32
|
+
size_t new_freed;
|
33
|
+
void* pointers[256];
|
34
|
+
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
|
35
|
+
} MemoryManager;
|
36
|
+
|
37
|
+
BROTLI_INTERNAL void BrotliInitMemoryManager(
|
38
|
+
MemoryManager* m, brotli_alloc_func alloc_func, brotli_free_func free_func,
|
39
|
+
void* opaque);
|
40
|
+
|
41
|
+
BROTLI_INTERNAL void* BrotliAllocate(MemoryManager* m, size_t n);
|
42
|
+
#define BROTLI_ALLOC(M, T, N) ((T*)BrotliAllocate((M), (N) * sizeof(T)))
|
43
|
+
|
44
|
+
BROTLI_INTERNAL void BrotliFree(MemoryManager* m, void* p);
|
45
|
+
#define BROTLI_FREE(M, P) { \
|
46
|
+
BrotliFree((M), (P)); \
|
47
|
+
P = NULL; \
|
48
|
+
}
|
49
|
+
|
50
|
+
#if defined(BROTLI_ENCODER_EXIT_ON_OOM)
|
51
|
+
#define BROTLI_IS_OOM(M) (!!0)
|
52
|
+
#else /* BROTLI_ENCODER_EXIT_ON_OOM */
|
53
|
+
#define BROTLI_IS_OOM(M) (!!(M)->is_oom)
|
54
|
+
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
|
55
|
+
|
56
|
+
BROTLI_INTERNAL void BrotliWipeOutMemoryManager(MemoryManager* m);
|
57
|
+
|
58
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
59
|
+
} /* extern "C" */
|
60
|
+
#endif
|
61
|
+
|
62
|
+
#endif /* BROTLI_ENC_MEMORY_H_ */
|