brotli 0.2.3 → 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.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +34 -0
- data/.github/workflows/publish.yml +34 -0
- data/Gemfile +6 -3
- data/Rakefile +16 -9
- data/brotli.gemspec +7 -13
- data/ext/brotli/brotli.c +209 -31
- data/ext/brotli/buffer.c +1 -7
- data/ext/brotli/buffer.h +1 -1
- data/ext/brotli/extconf.rb +20 -18
- data/lib/brotli/version.rb +1 -1
- data/test/brotli_test.rb +104 -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 +136 -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 +10 -1
- data/vendor/brotli/c/common/platform.c +22 -0
- data/vendor/brotli/c/common/platform.h +43 -17
- data/vendor/brotli/c/common/transform.c +59 -3
- data/vendor/brotli/c/common/transform.h +5 -0
- data/vendor/brotli/c/common/version.h +2 -2
- data/vendor/brotli/c/dec/bit_reader.c +28 -0
- data/vendor/brotli/c/dec/bit_reader.h +58 -16
- data/vendor/brotli/c/dec/decode.c +353 -251
- data/vendor/brotli/c/dec/huffman.h +6 -12
- data/vendor/brotli/c/dec/prefix.h +0 -18
- data/vendor/brotli/c/dec/state.c +9 -14
- data/vendor/brotli/c/dec/state.h +144 -37
- data/vendor/brotli/c/enc/backward_references.c +8 -7
- data/vendor/brotli/c/enc/backward_references.h +5 -4
- data/vendor/brotli/c/enc/backward_references_hq.c +51 -33
- data/vendor/brotli/c/enc/backward_references_hq.h +11 -8
- data/vendor/brotli/c/enc/backward_references_inc.h +24 -14
- data/vendor/brotli/c/enc/block_splitter.c +3 -3
- data/vendor/brotli/c/enc/block_splitter_inc.h +15 -6
- data/vendor/brotli/c/enc/brotli_bit_stream.c +13 -30
- data/vendor/brotli/c/enc/cluster_inc.h +6 -3
- data/vendor/brotli/c/enc/command.c +28 -0
- data/vendor/brotli/c/enc/command.h +12 -12
- data/vendor/brotli/c/enc/compress_fragment_two_pass.c +1 -1
- data/vendor/brotli/c/enc/dictionary_hash.c +1826 -1100
- data/vendor/brotli/c/enc/dictionary_hash.h +2 -1
- data/vendor/brotli/c/enc/encode.c +104 -39
- data/vendor/brotli/c/enc/encoder_dict.c +3 -2
- data/vendor/brotli/c/enc/encoder_dict.h +3 -1
- data/vendor/brotli/c/enc/entropy_encode.c +2 -0
- data/vendor/brotli/c/enc/entropy_encode.h +2 -2
- data/vendor/brotli/c/enc/fast_log.c +105 -0
- data/vendor/brotli/c/enc/fast_log.h +19 -100
- data/vendor/brotli/c/enc/find_match_length.h +2 -3
- data/vendor/brotli/c/enc/hash.h +80 -90
- data/vendor/brotli/c/enc/hash_composite_inc.h +52 -63
- data/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +88 -49
- data/vendor/brotli/c/enc/hash_longest_match64_inc.h +50 -50
- data/vendor/brotli/c/enc/hash_longest_match_inc.h +53 -50
- data/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +91 -60
- data/vendor/brotli/c/enc/hash_rolling_inc.h +23 -27
- data/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +39 -38
- data/vendor/brotli/c/enc/memory.h +24 -12
- data/vendor/brotli/c/enc/metablock.c +23 -27
- data/vendor/brotli/c/enc/metablock_inc.h +1 -1
- data/vendor/brotli/c/enc/params.h +3 -1
- data/vendor/brotli/c/enc/ringbuffer.h +4 -1
- data/vendor/brotli/c/enc/utf8_util.c +1 -1
- data/vendor/brotli/c/enc/write_bits.h +27 -25
- data/vendor/brotli/c/include/brotli/encode.h +22 -1
- data/vendor/brotli/c/include/brotli/port.h +14 -0
- metadata +17 -97
- data/.travis.yml +0 -31
- data/docs/Brotli.html +0 -485
- data/docs/Brotli/Error.html +0 -124
- 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
@@ -76,12 +76,12 @@ BROTLI_INTERNAL void BrotliConvertBitDepthsToSymbols(const uint8_t* depth,
|
|
76
76
|
size_t len,
|
77
77
|
uint16_t* bits);
|
78
78
|
|
79
|
+
BROTLI_INTERNAL extern const size_t kBrotliShellGaps[6];
|
79
80
|
/* Input size optimized Shell sort. */
|
80
81
|
typedef BROTLI_BOOL (*HuffmanTreeComparator)(
|
81
82
|
const HuffmanTree*, const HuffmanTree*);
|
82
83
|
static BROTLI_INLINE void SortHuffmanTreeItems(HuffmanTree* items,
|
83
84
|
const size_t n, HuffmanTreeComparator comparator) {
|
84
|
-
static const size_t gaps[] = {132, 57, 23, 10, 4, 1};
|
85
85
|
if (n < 13) {
|
86
86
|
/* Insertion sort. */
|
87
87
|
size_t i;
|
@@ -101,7 +101,7 @@ static BROTLI_INLINE void SortHuffmanTreeItems(HuffmanTree* items,
|
|
101
101
|
/* Shell sort. */
|
102
102
|
int g = n < 57 ? 2 : 0;
|
103
103
|
for (; g < 6; ++g) {
|
104
|
-
size_t gap =
|
104
|
+
size_t gap = kBrotliShellGaps[g];
|
105
105
|
size_t i;
|
106
106
|
for (i = gap; i < n; ++i) {
|
107
107
|
size_t j = i;
|
@@ -0,0 +1,105 @@
|
|
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
|
+
#include "./fast_log.h"
|
8
|
+
|
9
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
10
|
+
extern "C" {
|
11
|
+
#endif
|
12
|
+
|
13
|
+
/* ", ".join(["%.16ff" % x for x in [0.0]+[log2(x) for x in range(1, 256)]]) */
|
14
|
+
const double kBrotliLog2Table[BROTLI_LOG2_TABLE_SIZE] = {
|
15
|
+
0.0000000000000000f, 0.0000000000000000f, 1.0000000000000000f,
|
16
|
+
1.5849625007211563f, 2.0000000000000000f, 2.3219280948873622f,
|
17
|
+
2.5849625007211561f, 2.8073549220576042f, 3.0000000000000000f,
|
18
|
+
3.1699250014423126f, 3.3219280948873626f, 3.4594316186372978f,
|
19
|
+
3.5849625007211565f, 3.7004397181410922f, 3.8073549220576037f,
|
20
|
+
3.9068905956085187f, 4.0000000000000000f, 4.0874628412503400f,
|
21
|
+
4.1699250014423122f, 4.2479275134435852f, 4.3219280948873626f,
|
22
|
+
4.3923174227787607f, 4.4594316186372973f, 4.5235619560570131f,
|
23
|
+
4.5849625007211570f, 4.6438561897747244f, 4.7004397181410926f,
|
24
|
+
4.7548875021634691f, 4.8073549220576037f, 4.8579809951275728f,
|
25
|
+
4.9068905956085187f, 4.9541963103868758f, 5.0000000000000000f,
|
26
|
+
5.0443941193584534f, 5.0874628412503400f, 5.1292830169449664f,
|
27
|
+
5.1699250014423122f, 5.2094533656289501f, 5.2479275134435852f,
|
28
|
+
5.2854022188622487f, 5.3219280948873626f, 5.3575520046180838f,
|
29
|
+
5.3923174227787607f, 5.4262647547020979f, 5.4594316186372973f,
|
30
|
+
5.4918530963296748f, 5.5235619560570131f, 5.5545888516776376f,
|
31
|
+
5.5849625007211570f, 5.6147098441152083f, 5.6438561897747244f,
|
32
|
+
5.6724253419714961f, 5.7004397181410926f, 5.7279204545631996f,
|
33
|
+
5.7548875021634691f, 5.7813597135246599f, 5.8073549220576046f,
|
34
|
+
5.8328900141647422f, 5.8579809951275719f, 5.8826430493618416f,
|
35
|
+
5.9068905956085187f, 5.9307373375628867f, 5.9541963103868758f,
|
36
|
+
5.9772799234999168f, 6.0000000000000000f, 6.0223678130284544f,
|
37
|
+
6.0443941193584534f, 6.0660891904577721f, 6.0874628412503400f,
|
38
|
+
6.1085244567781700f, 6.1292830169449672f, 6.1497471195046822f,
|
39
|
+
6.1699250014423122f, 6.1898245588800176f, 6.2094533656289510f,
|
40
|
+
6.2288186904958804f, 6.2479275134435861f, 6.2667865406949019f,
|
41
|
+
6.2854022188622487f, 6.3037807481771031f, 6.3219280948873617f,
|
42
|
+
6.3398500028846252f, 6.3575520046180847f, 6.3750394313469254f,
|
43
|
+
6.3923174227787598f, 6.4093909361377026f, 6.4262647547020979f,
|
44
|
+
6.4429434958487288f, 6.4594316186372982f, 6.4757334309663976f,
|
45
|
+
6.4918530963296748f, 6.5077946401986964f, 6.5235619560570131f,
|
46
|
+
6.5391588111080319f, 6.5545888516776376f, 6.5698556083309478f,
|
47
|
+
6.5849625007211561f, 6.5999128421871278f, 6.6147098441152092f,
|
48
|
+
6.6293566200796095f, 6.6438561897747253f, 6.6582114827517955f,
|
49
|
+
6.6724253419714952f, 6.6865005271832185f, 6.7004397181410917f,
|
50
|
+
6.7142455176661224f, 6.7279204545631988f, 6.7414669864011465f,
|
51
|
+
6.7548875021634691f, 6.7681843247769260f, 6.7813597135246599f,
|
52
|
+
6.7944158663501062f, 6.8073549220576037f, 6.8201789624151887f,
|
53
|
+
6.8328900141647422f, 6.8454900509443757f, 6.8579809951275719f,
|
54
|
+
6.8703647195834048f, 6.8826430493618416f, 6.8948177633079437f,
|
55
|
+
6.9068905956085187f, 6.9188632372745955f, 6.9307373375628867f,
|
56
|
+
6.9425145053392399f, 6.9541963103868758f, 6.9657842846620879f,
|
57
|
+
6.9772799234999168f, 6.9886846867721664f, 7.0000000000000000f,
|
58
|
+
7.0112272554232540f, 7.0223678130284544f, 7.0334230015374501f,
|
59
|
+
7.0443941193584534f, 7.0552824355011898f, 7.0660891904577721f,
|
60
|
+
7.0768155970508317f, 7.0874628412503400f, 7.0980320829605272f,
|
61
|
+
7.1085244567781700f, 7.1189410727235076f, 7.1292830169449664f,
|
62
|
+
7.1395513523987937f, 7.1497471195046822f, 7.1598713367783891f,
|
63
|
+
7.1699250014423130f, 7.1799090900149345f, 7.1898245588800176f,
|
64
|
+
7.1996723448363644f, 7.2094533656289492f, 7.2191685204621621f,
|
65
|
+
7.2288186904958804f, 7.2384047393250794f, 7.2479275134435861f,
|
66
|
+
7.2573878426926521f, 7.2667865406949019f, 7.2761244052742384f,
|
67
|
+
7.2854022188622487f, 7.2946207488916270f, 7.3037807481771031f,
|
68
|
+
7.3128829552843557f, 7.3219280948873617f, 7.3309168781146177f,
|
69
|
+
7.3398500028846243f, 7.3487281542310781f, 7.3575520046180847f,
|
70
|
+
7.3663222142458151f, 7.3750394313469254f, 7.3837042924740528f,
|
71
|
+
7.3923174227787607f, 7.4008794362821844f, 7.4093909361377026f,
|
72
|
+
7.4178525148858991f, 7.4262647547020979f, 7.4346282276367255f,
|
73
|
+
7.4429434958487288f, 7.4512111118323299f, 7.4594316186372973f,
|
74
|
+
7.4676055500829976f, 7.4757334309663976f, 7.4838157772642564f,
|
75
|
+
7.4918530963296748f, 7.4998458870832057f, 7.5077946401986964f,
|
76
|
+
7.5156998382840436f, 7.5235619560570131f, 7.5313814605163119f,
|
77
|
+
7.5391588111080319f, 7.5468944598876373f, 7.5545888516776376f,
|
78
|
+
7.5622424242210728f, 7.5698556083309478f, 7.5774288280357487f,
|
79
|
+
7.5849625007211561f, 7.5924570372680806f, 7.5999128421871278f,
|
80
|
+
7.6073303137496113f, 7.6147098441152075f, 7.6220518194563764f,
|
81
|
+
7.6293566200796095f, 7.6366246205436488f, 7.6438561897747244f,
|
82
|
+
7.6510516911789290f, 7.6582114827517955f, 7.6653359171851765f,
|
83
|
+
7.6724253419714952f, 7.6794800995054464f, 7.6865005271832185f,
|
84
|
+
7.6934869574993252f, 7.7004397181410926f, 7.7073591320808825f,
|
85
|
+
7.7142455176661224f, 7.7210991887071856f, 7.7279204545631996f,
|
86
|
+
7.7347096202258392f, 7.7414669864011465f, 7.7481928495894596f,
|
87
|
+
7.7548875021634691f, 7.7615512324444795f, 7.7681843247769260f,
|
88
|
+
7.7747870596011737f, 7.7813597135246608f, 7.7879025593914317f,
|
89
|
+
7.7944158663501062f, 7.8008998999203047f, 7.8073549220576037f,
|
90
|
+
7.8137811912170374f, 7.8201789624151887f, 7.8265484872909159f,
|
91
|
+
7.8328900141647422f, 7.8392037880969445f, 7.8454900509443757f,
|
92
|
+
7.8517490414160571f, 7.8579809951275719f, 7.8641861446542798f,
|
93
|
+
7.8703647195834048f, 7.8765169465650002f, 7.8826430493618425f,
|
94
|
+
7.8887432488982601f, 7.8948177633079446f, 7.9008668079807496f,
|
95
|
+
7.9068905956085187f, 7.9128893362299619f, 7.9188632372745955f,
|
96
|
+
7.9248125036057813f, 7.9307373375628867f, 7.9366379390025719f,
|
97
|
+
7.9425145053392399f, 7.9483672315846778f, 7.9541963103868758f,
|
98
|
+
7.9600019320680806f, 7.9657842846620870f, 7.9715435539507720f,
|
99
|
+
7.9772799234999168f, 7.9829935746943104f, 7.9886846867721664f,
|
100
|
+
7.9943534368588578f
|
101
|
+
};
|
102
|
+
|
103
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
104
|
+
} /* extern "C" */
|
105
|
+
#endif
|
@@ -19,10 +19,8 @@ extern "C" {
|
|
19
19
|
#endif
|
20
20
|
|
21
21
|
static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) {
|
22
|
-
|
23
|
-
|
24
|
-
BROTLI_INTEL_VERSION_CHECK(16, 0, 0)
|
25
|
-
return 31u ^ (uint32_t)__builtin_clz((uint32_t)n);
|
22
|
+
#if defined(BROTLI_BSR32)
|
23
|
+
return BROTLI_BSR32((uint32_t)n);
|
26
24
|
#else
|
27
25
|
uint32_t result = 0;
|
28
26
|
while (n >>= 1) result++;
|
@@ -30,110 +28,31 @@ static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) {
|
|
30
28
|
#endif
|
31
29
|
}
|
32
30
|
|
31
|
+
#define BROTLI_LOG2_TABLE_SIZE 256
|
32
|
+
|
33
33
|
/* A lookup table for small values of log2(int) to be used in entropy
|
34
|
-
computation.
|
34
|
+
computation. */
|
35
|
+
BROTLI_INTERNAL extern const double kBrotliLog2Table[BROTLI_LOG2_TABLE_SIZE];
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
4.5849625007211570f, 4.6438561897747244f, 4.7004397181410926f,
|
47
|
-
4.7548875021634691f, 4.8073549220576037f, 4.8579809951275728f,
|
48
|
-
4.9068905956085187f, 4.9541963103868758f, 5.0000000000000000f,
|
49
|
-
5.0443941193584534f, 5.0874628412503400f, 5.1292830169449664f,
|
50
|
-
5.1699250014423122f, 5.2094533656289501f, 5.2479275134435852f,
|
51
|
-
5.2854022188622487f, 5.3219280948873626f, 5.3575520046180838f,
|
52
|
-
5.3923174227787607f, 5.4262647547020979f, 5.4594316186372973f,
|
53
|
-
5.4918530963296748f, 5.5235619560570131f, 5.5545888516776376f,
|
54
|
-
5.5849625007211570f, 5.6147098441152083f, 5.6438561897747244f,
|
55
|
-
5.6724253419714961f, 5.7004397181410926f, 5.7279204545631996f,
|
56
|
-
5.7548875021634691f, 5.7813597135246599f, 5.8073549220576046f,
|
57
|
-
5.8328900141647422f, 5.8579809951275719f, 5.8826430493618416f,
|
58
|
-
5.9068905956085187f, 5.9307373375628867f, 5.9541963103868758f,
|
59
|
-
5.9772799234999168f, 6.0000000000000000f, 6.0223678130284544f,
|
60
|
-
6.0443941193584534f, 6.0660891904577721f, 6.0874628412503400f,
|
61
|
-
6.1085244567781700f, 6.1292830169449672f, 6.1497471195046822f,
|
62
|
-
6.1699250014423122f, 6.1898245588800176f, 6.2094533656289510f,
|
63
|
-
6.2288186904958804f, 6.2479275134435861f, 6.2667865406949019f,
|
64
|
-
6.2854022188622487f, 6.3037807481771031f, 6.3219280948873617f,
|
65
|
-
6.3398500028846252f, 6.3575520046180847f, 6.3750394313469254f,
|
66
|
-
6.3923174227787598f, 6.4093909361377026f, 6.4262647547020979f,
|
67
|
-
6.4429434958487288f, 6.4594316186372982f, 6.4757334309663976f,
|
68
|
-
6.4918530963296748f, 6.5077946401986964f, 6.5235619560570131f,
|
69
|
-
6.5391588111080319f, 6.5545888516776376f, 6.5698556083309478f,
|
70
|
-
6.5849625007211561f, 6.5999128421871278f, 6.6147098441152092f,
|
71
|
-
6.6293566200796095f, 6.6438561897747253f, 6.6582114827517955f,
|
72
|
-
6.6724253419714952f, 6.6865005271832185f, 6.7004397181410917f,
|
73
|
-
6.7142455176661224f, 6.7279204545631988f, 6.7414669864011465f,
|
74
|
-
6.7548875021634691f, 6.7681843247769260f, 6.7813597135246599f,
|
75
|
-
6.7944158663501062f, 6.8073549220576037f, 6.8201789624151887f,
|
76
|
-
6.8328900141647422f, 6.8454900509443757f, 6.8579809951275719f,
|
77
|
-
6.8703647195834048f, 6.8826430493618416f, 6.8948177633079437f,
|
78
|
-
6.9068905956085187f, 6.9188632372745955f, 6.9307373375628867f,
|
79
|
-
6.9425145053392399f, 6.9541963103868758f, 6.9657842846620879f,
|
80
|
-
6.9772799234999168f, 6.9886846867721664f, 7.0000000000000000f,
|
81
|
-
7.0112272554232540f, 7.0223678130284544f, 7.0334230015374501f,
|
82
|
-
7.0443941193584534f, 7.0552824355011898f, 7.0660891904577721f,
|
83
|
-
7.0768155970508317f, 7.0874628412503400f, 7.0980320829605272f,
|
84
|
-
7.1085244567781700f, 7.1189410727235076f, 7.1292830169449664f,
|
85
|
-
7.1395513523987937f, 7.1497471195046822f, 7.1598713367783891f,
|
86
|
-
7.1699250014423130f, 7.1799090900149345f, 7.1898245588800176f,
|
87
|
-
7.1996723448363644f, 7.2094533656289492f, 7.2191685204621621f,
|
88
|
-
7.2288186904958804f, 7.2384047393250794f, 7.2479275134435861f,
|
89
|
-
7.2573878426926521f, 7.2667865406949019f, 7.2761244052742384f,
|
90
|
-
7.2854022188622487f, 7.2946207488916270f, 7.3037807481771031f,
|
91
|
-
7.3128829552843557f, 7.3219280948873617f, 7.3309168781146177f,
|
92
|
-
7.3398500028846243f, 7.3487281542310781f, 7.3575520046180847f,
|
93
|
-
7.3663222142458151f, 7.3750394313469254f, 7.3837042924740528f,
|
94
|
-
7.3923174227787607f, 7.4008794362821844f, 7.4093909361377026f,
|
95
|
-
7.4178525148858991f, 7.4262647547020979f, 7.4346282276367255f,
|
96
|
-
7.4429434958487288f, 7.4512111118323299f, 7.4594316186372973f,
|
97
|
-
7.4676055500829976f, 7.4757334309663976f, 7.4838157772642564f,
|
98
|
-
7.4918530963296748f, 7.4998458870832057f, 7.5077946401986964f,
|
99
|
-
7.5156998382840436f, 7.5235619560570131f, 7.5313814605163119f,
|
100
|
-
7.5391588111080319f, 7.5468944598876373f, 7.5545888516776376f,
|
101
|
-
7.5622424242210728f, 7.5698556083309478f, 7.5774288280357487f,
|
102
|
-
7.5849625007211561f, 7.5924570372680806f, 7.5999128421871278f,
|
103
|
-
7.6073303137496113f, 7.6147098441152075f, 7.6220518194563764f,
|
104
|
-
7.6293566200796095f, 7.6366246205436488f, 7.6438561897747244f,
|
105
|
-
7.6510516911789290f, 7.6582114827517955f, 7.6653359171851765f,
|
106
|
-
7.6724253419714952f, 7.6794800995054464f, 7.6865005271832185f,
|
107
|
-
7.6934869574993252f, 7.7004397181410926f, 7.7073591320808825f,
|
108
|
-
7.7142455176661224f, 7.7210991887071856f, 7.7279204545631996f,
|
109
|
-
7.7347096202258392f, 7.7414669864011465f, 7.7481928495894596f,
|
110
|
-
7.7548875021634691f, 7.7615512324444795f, 7.7681843247769260f,
|
111
|
-
7.7747870596011737f, 7.7813597135246608f, 7.7879025593914317f,
|
112
|
-
7.7944158663501062f, 7.8008998999203047f, 7.8073549220576037f,
|
113
|
-
7.8137811912170374f, 7.8201789624151887f, 7.8265484872909159f,
|
114
|
-
7.8328900141647422f, 7.8392037880969445f, 7.8454900509443757f,
|
115
|
-
7.8517490414160571f, 7.8579809951275719f, 7.8641861446542798f,
|
116
|
-
7.8703647195834048f, 7.8765169465650002f, 7.8826430493618425f,
|
117
|
-
7.8887432488982601f, 7.8948177633079446f, 7.9008668079807496f,
|
118
|
-
7.9068905956085187f, 7.9128893362299619f, 7.9188632372745955f,
|
119
|
-
7.9248125036057813f, 7.9307373375628867f, 7.9366379390025719f,
|
120
|
-
7.9425145053392399f, 7.9483672315846778f, 7.9541963103868758f,
|
121
|
-
7.9600019320680806f, 7.9657842846620870f, 7.9715435539507720f,
|
122
|
-
7.9772799234999168f, 7.9829935746943104f, 7.9886846867721664f,
|
123
|
-
7.9943534368588578f
|
124
|
-
};
|
37
|
+
/* Visual Studio 2012 and Android API levels < 18 do not have the log2()
|
38
|
+
* function defined, so we use log() and a multiplication instead. */
|
39
|
+
#if !defined(BROTLI_HAVE_LOG2)
|
40
|
+
#if ((defined(_MSC_VER) && _MSC_VER <= 1700) || \
|
41
|
+
(defined(__ANDROID_API__) && __ANDROID_API__ < 18))
|
42
|
+
#define BROTLI_HAVE_LOG2 0
|
43
|
+
#else
|
44
|
+
#define BROTLI_HAVE_LOG2 1
|
45
|
+
#endif
|
46
|
+
#endif
|
125
47
|
|
126
48
|
#define LOG_2_INV 1.4426950408889634
|
127
49
|
|
128
50
|
/* Faster logarithm for small integers, with the property of log2(0) == 0. */
|
129
51
|
static BROTLI_INLINE double FastLog2(size_t v) {
|
130
|
-
if (v <
|
131
|
-
return
|
52
|
+
if (v < BROTLI_LOG2_TABLE_SIZE) {
|
53
|
+
return kBrotliLog2Table[v];
|
132
54
|
}
|
133
|
-
#if (
|
134
|
-
(defined(__ANDROID_API__) && __ANDROID_API__ < 18)
|
135
|
-
/* Visual Studio 2012 and Android API levels < 18 do not have the log2()
|
136
|
-
* function defined, so we use log() and a multiplication instead. */
|
55
|
+
#if !(BROTLI_HAVE_LOG2)
|
137
56
|
return log((double)v) * LOG_2_INV;
|
138
57
|
#else
|
139
58
|
return log2((double)v);
|
@@ -17,8 +17,7 @@ extern "C" {
|
|
17
17
|
#endif
|
18
18
|
|
19
19
|
/* Separate implementation for little-endian 64-bit targets, for speed. */
|
20
|
-
#if defined(
|
21
|
-
|
20
|
+
#if defined(BROTLI_TZCNT64) && BROTLI_64_BITS && BROTLI_LITTLE_ENDIAN
|
22
21
|
static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,
|
23
22
|
const uint8_t* s2,
|
24
23
|
size_t limit) {
|
@@ -32,7 +31,7 @@ static BROTLI_INLINE size_t FindMatchLengthWithLimit(const uint8_t* s1,
|
|
32
31
|
} else {
|
33
32
|
uint64_t x = BROTLI_UNALIGNED_LOAD64LE(s2) ^
|
34
33
|
BROTLI_UNALIGNED_LOAD64LE(s1 + matched);
|
35
|
-
size_t matching_bits = (size_t)
|
34
|
+
size_t matching_bits = (size_t)BROTLI_TZCNT64(x);
|
36
35
|
matched += matching_bits >> 3;
|
37
36
|
return matched;
|
38
37
|
}
|
data/vendor/brotli/c/enc/hash.h
CHANGED
@@ -27,34 +27,19 @@
|
|
27
27
|
extern "C" {
|
28
28
|
#endif
|
29
29
|
|
30
|
-
/* Pointer to hasher data.
|
31
|
-
*
|
32
|
-
* Excluding initialization and destruction, hasher can be passed as
|
33
|
-
* HasherHandle by value.
|
34
|
-
*
|
35
|
-
* Typically hasher data consists of 3 sections:
|
36
|
-
* * HasherCommon structure
|
37
|
-
* * private structured hasher data, depending on hasher type
|
38
|
-
* * private dynamic hasher data, depending on hasher type and parameters
|
39
|
-
*
|
40
|
-
* Using "define" instead of "typedef", because on MSVC __restrict does not work
|
41
|
-
* on typedef pointer types. */
|
42
|
-
#define HasherHandle uint8_t*
|
43
|
-
|
44
30
|
typedef struct {
|
31
|
+
/* Dynamically allocated area; first member for quickest access. */
|
32
|
+
void* extra;
|
33
|
+
|
34
|
+
size_t dict_num_lookups;
|
35
|
+
size_t dict_num_matches;
|
36
|
+
|
45
37
|
BrotliHasherParams params;
|
46
38
|
|
47
39
|
/* False if hasher needs to be "prepared" before use. */
|
48
40
|
BROTLI_BOOL is_prepared_;
|
49
|
-
|
50
|
-
size_t dict_num_lookups;
|
51
|
-
size_t dict_num_matches;
|
52
41
|
} HasherCommon;
|
53
42
|
|
54
|
-
static BROTLI_INLINE HasherCommon* GetHasherCommon(HasherHandle handle) {
|
55
|
-
return (HasherCommon*)handle;
|
56
|
-
}
|
57
|
-
|
58
43
|
#define score_t size_t
|
59
44
|
|
60
45
|
static const uint32_t kCutoffTransformsCount = 10;
|
@@ -149,17 +134,13 @@ static BROTLI_INLINE score_t BackwardReferencePenaltyUsingLastDistance(
|
|
149
134
|
}
|
150
135
|
|
151
136
|
static BROTLI_INLINE BROTLI_BOOL TestStaticDictionaryItem(
|
152
|
-
const BrotliEncoderDictionary* dictionary, size_t
|
137
|
+
const BrotliEncoderDictionary* dictionary, size_t len, size_t word_idx,
|
153
138
|
const uint8_t* data, size_t max_length, size_t max_backward,
|
154
139
|
size_t max_distance, HasherSearchResult* out) {
|
155
|
-
size_t len;
|
156
|
-
size_t word_idx;
|
157
140
|
size_t offset;
|
158
141
|
size_t matchlen;
|
159
142
|
size_t backward;
|
160
143
|
score_t score;
|
161
|
-
len = item & 0x1F;
|
162
|
-
word_idx = item >> 5;
|
163
144
|
offset = dictionary->words->offsets_by_length[len] + len * word_idx;
|
164
145
|
if (len > max_length) {
|
165
146
|
return BROTLI_FALSE;
|
@@ -193,25 +174,24 @@ static BROTLI_INLINE BROTLI_BOOL TestStaticDictionaryItem(
|
|
193
174
|
|
194
175
|
static BROTLI_INLINE void SearchInStaticDictionary(
|
195
176
|
const BrotliEncoderDictionary* dictionary,
|
196
|
-
|
177
|
+
HasherCommon* common, const uint8_t* data, size_t max_length,
|
197
178
|
size_t max_backward, size_t max_distance,
|
198
179
|
HasherSearchResult* out, BROTLI_BOOL shallow) {
|
199
180
|
size_t key;
|
200
181
|
size_t i;
|
201
|
-
|
202
|
-
if (self->dict_num_matches < (self->dict_num_lookups >> 7)) {
|
182
|
+
if (common->dict_num_matches < (common->dict_num_lookups >> 7)) {
|
203
183
|
return;
|
204
184
|
}
|
205
185
|
key = Hash14(data) << 1;
|
206
186
|
for (i = 0; i < (shallow ? 1u : 2u); ++i, ++key) {
|
207
|
-
|
208
|
-
|
209
|
-
if (item != 0) {
|
187
|
+
common->dict_num_lookups++;
|
188
|
+
if (dictionary->hash_table_lengths[key] != 0) {
|
210
189
|
BROTLI_BOOL item_matches = TestStaticDictionaryItem(
|
211
|
-
dictionary,
|
190
|
+
dictionary, dictionary->hash_table_lengths[key],
|
191
|
+
dictionary->hash_table_words[key], data,
|
212
192
|
max_length, max_backward, max_distance, out);
|
213
193
|
if (item_matches) {
|
214
|
-
|
194
|
+
common->dict_num_matches++;
|
215
195
|
}
|
216
196
|
}
|
217
197
|
}
|
@@ -260,37 +240,37 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) {
|
|
260
240
|
/* MAX_NUM_MATCHES == 64 + MAX_TREE_SEARCH_DEPTH */
|
261
241
|
#define MAX_NUM_MATCHES_H10 128
|
262
242
|
|
263
|
-
/* For
|
243
|
+
/* For BUCKET_SWEEP_BITS == 0, enabling the dictionary lookup makes compression
|
264
244
|
a little faster (0.5% - 1%) and it compresses 0.15% better on small text
|
265
245
|
and HTML inputs. */
|
266
246
|
|
267
247
|
#define HASHER() H2
|
268
248
|
#define BUCKET_BITS 16
|
269
|
-
#define
|
249
|
+
#define BUCKET_SWEEP_BITS 0
|
270
250
|
#define HASH_LEN 5
|
271
251
|
#define USE_DICTIONARY 1
|
272
252
|
#include "./hash_longest_match_quickly_inc.h" /* NOLINT(build/include) */
|
273
|
-
#undef
|
253
|
+
#undef BUCKET_SWEEP_BITS
|
274
254
|
#undef USE_DICTIONARY
|
275
255
|
#undef HASHER
|
276
256
|
|
277
257
|
#define HASHER() H3
|
278
|
-
#define
|
258
|
+
#define BUCKET_SWEEP_BITS 1
|
279
259
|
#define USE_DICTIONARY 0
|
280
260
|
#include "./hash_longest_match_quickly_inc.h" /* NOLINT(build/include) */
|
281
261
|
#undef USE_DICTIONARY
|
282
|
-
#undef
|
262
|
+
#undef BUCKET_SWEEP_BITS
|
283
263
|
#undef BUCKET_BITS
|
284
264
|
#undef HASHER
|
285
265
|
|
286
266
|
#define HASHER() H4
|
287
267
|
#define BUCKET_BITS 17
|
288
|
-
#define
|
268
|
+
#define BUCKET_SWEEP_BITS 2
|
289
269
|
#define USE_DICTIONARY 1
|
290
270
|
#include "./hash_longest_match_quickly_inc.h" /* NOLINT(build/include) */
|
291
271
|
#undef USE_DICTIONARY
|
292
272
|
#undef HASH_LEN
|
293
|
-
#undef
|
273
|
+
#undef BUCKET_SWEEP_BITS
|
294
274
|
#undef BUCKET_BITS
|
295
275
|
#undef HASHER
|
296
276
|
|
@@ -334,13 +314,13 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) {
|
|
334
314
|
|
335
315
|
#define HASHER() H54
|
336
316
|
#define BUCKET_BITS 20
|
337
|
-
#define
|
317
|
+
#define BUCKET_SWEEP_BITS 2
|
338
318
|
#define HASH_LEN 7
|
339
319
|
#define USE_DICTIONARY 0
|
340
320
|
#include "./hash_longest_match_quickly_inc.h" /* NOLINT(build/include) */
|
341
321
|
#undef USE_DICTIONARY
|
342
322
|
#undef HASH_LEN
|
343
|
-
#undef
|
323
|
+
#undef BUCKET_SWEEP_BITS
|
344
324
|
#undef BUCKET_BITS
|
345
325
|
#undef HASHER
|
346
326
|
|
@@ -393,97 +373,107 @@ static BROTLI_INLINE size_t BackwardMatchLengthCode(const BackwardMatch* self) {
|
|
393
373
|
#undef CAT
|
394
374
|
#undef EXPAND_CAT
|
395
375
|
|
396
|
-
#define
|
397
|
-
|
376
|
+
#define FOR_SIMPLE_HASHERS(H) H(2) H(3) H(4) H(5) H(6) H(40) H(41) H(42) H(54)
|
377
|
+
#define FOR_COMPOSITE_HASHERS(H) H(35) H(55) H(65)
|
378
|
+
#define FOR_GENERIC_HASHERS(H) FOR_SIMPLE_HASHERS(H) FOR_COMPOSITE_HASHERS(H)
|
398
379
|
#define FOR_ALL_HASHERS(H) FOR_GENERIC_HASHERS(H) H(10)
|
399
380
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
381
|
+
typedef struct {
|
382
|
+
HasherCommon common;
|
383
|
+
|
384
|
+
union {
|
385
|
+
#define MEMBER_(N) \
|
386
|
+
H ## N _H ## N;
|
387
|
+
FOR_ALL_HASHERS(MEMBER_)
|
388
|
+
#undef MEMBER_
|
389
|
+
} privat;
|
390
|
+
} Hasher;
|
391
|
+
|
392
|
+
/* MUST be invoked before any other method. */
|
393
|
+
static BROTLI_INLINE void HasherInit(Hasher* hasher) {
|
394
|
+
hasher->common.extra = NULL;
|
404
395
|
}
|
405
396
|
|
406
|
-
static BROTLI_INLINE void
|
407
|
-
if (
|
408
|
-
|
397
|
+
static BROTLI_INLINE void DestroyHasher(MemoryManager* m, Hasher* hasher) {
|
398
|
+
if (hasher->common.extra == NULL) return;
|
399
|
+
BROTLI_FREE(m, hasher->common.extra);
|
400
|
+
}
|
401
|
+
|
402
|
+
static BROTLI_INLINE void HasherReset(Hasher* hasher) {
|
403
|
+
hasher->common.is_prepared_ = BROTLI_FALSE;
|
409
404
|
}
|
410
405
|
|
411
406
|
static BROTLI_INLINE size_t HasherSize(const BrotliEncoderParams* params,
|
412
407
|
BROTLI_BOOL one_shot, const size_t input_size) {
|
413
|
-
size_t result = sizeof(HasherCommon);
|
414
408
|
switch (params->hasher.type) {
|
415
|
-
#define SIZE_(N)
|
416
|
-
case N:
|
417
|
-
|
418
|
-
break;
|
409
|
+
#define SIZE_(N) \
|
410
|
+
case N: \
|
411
|
+
return HashMemAllocInBytesH ## N(params, one_shot, input_size);
|
419
412
|
FOR_ALL_HASHERS(SIZE_)
|
420
413
|
#undef SIZE_
|
421
414
|
default:
|
422
415
|
break;
|
423
416
|
}
|
424
|
-
return
|
417
|
+
return 0; /* Default case. */
|
425
418
|
}
|
426
419
|
|
427
|
-
static BROTLI_INLINE void HasherSetup(MemoryManager* m,
|
420
|
+
static BROTLI_INLINE void HasherSetup(MemoryManager* m, Hasher* hasher,
|
428
421
|
BrotliEncoderParams* params, const uint8_t* data, size_t position,
|
429
422
|
size_t input_size, BROTLI_BOOL is_last) {
|
430
|
-
HasherHandle self = NULL;
|
431
|
-
HasherCommon* common = NULL;
|
432
423
|
BROTLI_BOOL one_shot = (position == 0 && is_last);
|
433
|
-
if (
|
424
|
+
if (hasher->common.extra == NULL) {
|
434
425
|
size_t alloc_size;
|
435
426
|
ChooseHasher(params, ¶ms->hasher);
|
436
427
|
alloc_size = HasherSize(params, one_shot, input_size);
|
437
|
-
|
438
|
-
if (BROTLI_IS_OOM(m)) return;
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
InitializeH ## N(*handle, params); \
|
428
|
+
hasher->common.extra = BROTLI_ALLOC(m, uint8_t, alloc_size);
|
429
|
+
if (BROTLI_IS_OOM(m) || BROTLI_IS_NULL(hasher->common.extra)) return;
|
430
|
+
hasher->common.params = params->hasher;
|
431
|
+
switch (hasher->common.params.type) {
|
432
|
+
#define INITIALIZE_(N) \
|
433
|
+
case N: \
|
434
|
+
InitializeH ## N(&hasher->common, \
|
435
|
+
&hasher->privat._H ## N, params); \
|
446
436
|
break;
|
447
437
|
FOR_ALL_HASHERS(INITIALIZE_);
|
448
438
|
#undef INITIALIZE_
|
449
439
|
default:
|
450
440
|
break;
|
451
441
|
}
|
452
|
-
HasherReset(
|
442
|
+
HasherReset(hasher);
|
453
443
|
}
|
454
444
|
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
445
|
+
if (!hasher->common.is_prepared_) {
|
446
|
+
switch (hasher->common.params.type) {
|
447
|
+
#define PREPARE_(N) \
|
448
|
+
case N: \
|
449
|
+
PrepareH ## N( \
|
450
|
+
&hasher->privat._H ## N, \
|
451
|
+
one_shot, input_size, data); \
|
462
452
|
break;
|
463
453
|
FOR_ALL_HASHERS(PREPARE_)
|
464
454
|
#undef PREPARE_
|
465
455
|
default: break;
|
466
456
|
}
|
467
457
|
if (position == 0) {
|
468
|
-
|
469
|
-
|
458
|
+
hasher->common.dict_num_lookups = 0;
|
459
|
+
hasher->common.dict_num_matches = 0;
|
470
460
|
}
|
471
|
-
common
|
461
|
+
hasher->common.is_prepared_ = BROTLI_TRUE;
|
472
462
|
}
|
473
463
|
}
|
474
464
|
|
475
465
|
static BROTLI_INLINE void InitOrStitchToPreviousBlock(
|
476
|
-
MemoryManager* m,
|
466
|
+
MemoryManager* m, Hasher* hasher, const uint8_t* data, size_t mask,
|
477
467
|
BrotliEncoderParams* params, size_t position, size_t input_size,
|
478
468
|
BROTLI_BOOL is_last) {
|
479
|
-
|
480
|
-
HasherSetup(m, handle, params, data, position, input_size, is_last);
|
469
|
+
HasherSetup(m, hasher, params, data, position, input_size, is_last);
|
481
470
|
if (BROTLI_IS_OOM(m)) return;
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
471
|
+
switch (hasher->common.params.type) {
|
472
|
+
#define INIT_(N) \
|
473
|
+
case N: \
|
474
|
+
StitchToPreviousBlockH ## N( \
|
475
|
+
&hasher->privat._H ## N, \
|
476
|
+
input_size, position, data, mask); \
|
487
477
|
break;
|
488
478
|
FOR_ALL_HASHERS(INIT_)
|
489
479
|
#undef INIT_
|