zstd-ruby 1.3.0.0 → 1.3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/zstdruby/libzstd/common/bitstream.h +40 -41
- data/ext/zstdruby/libzstd/common/compiler.h +85 -0
- data/ext/zstdruby/libzstd/common/error_private.c +8 -10
- data/ext/zstdruby/libzstd/common/error_private.h +4 -4
- data/ext/zstdruby/libzstd/common/fse.h +11 -5
- data/ext/zstdruby/libzstd/common/fse_decompress.c +3 -22
- data/ext/zstdruby/libzstd/common/huf.h +5 -6
- data/ext/zstdruby/libzstd/common/mem.h +6 -6
- data/ext/zstdruby/libzstd/common/pool.c +61 -27
- data/ext/zstdruby/libzstd/common/pool.h +10 -10
- data/ext/zstdruby/libzstd/common/threading.h +5 -6
- data/ext/zstdruby/libzstd/common/xxhash.c +28 -22
- data/ext/zstdruby/libzstd/common/zstd_common.c +4 -4
- data/ext/zstdruby/libzstd/common/zstd_errors.h +30 -32
- data/ext/zstdruby/libzstd/common/zstd_internal.h +57 -56
- data/ext/zstdruby/libzstd/compress/fse_compress.c +4 -22
- data/ext/zstdruby/libzstd/compress/huf_compress.c +4 -3
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +314 -304
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +118 -116
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +223 -156
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +10 -9
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +8 -24
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +95 -115
- data/ext/zstdruby/libzstd/deprecated/zbuff.h +4 -4
- data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +4 -5
- data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +4 -4
- data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +4 -4
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +7 -9
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +5 -5
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +8 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +5 -5
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +5 -5
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +5 -5
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +4 -4
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +4 -4
- data/ext/zstdruby/libzstd/zstd.h +16 -14
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +3 -2
@@ -1,10 +1,10 @@
|
|
1
|
-
|
2
|
-
* Copyright (c) 2016-present,
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
6
|
-
* LICENSE file in the root directory of this source tree
|
7
|
-
*
|
5
|
+
* This source code is licensed under both the BSD-style license (found in the
|
6
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
|
+
* in the COPYING file in the root directory of this source tree).
|
8
8
|
*/
|
9
9
|
|
10
10
|
|
@@ -22,173 +22,173 @@
|
|
22
22
|
/*-*************************************
|
23
23
|
* Price functions for optimal parser
|
24
24
|
***************************************/
|
25
|
-
|
25
|
+
static void ZSTD_setLog2Prices(optState_t* optPtr)
|
26
26
|
{
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
optPtr->log2matchLengthSum = ZSTD_highbit32(optPtr->matchLengthSum+1);
|
28
|
+
optPtr->log2litLengthSum = ZSTD_highbit32(optPtr->litLengthSum+1);
|
29
|
+
optPtr->log2litSum = ZSTD_highbit32(optPtr->litSum+1);
|
30
|
+
optPtr->log2offCodeSum = ZSTD_highbit32(optPtr->offCodeSum+1);
|
31
|
+
optPtr->factor = 1 + ((optPtr->litSum>>5) / optPtr->litLengthSum) + ((optPtr->litSum<<1) / (optPtr->litSum + optPtr->matchSum));
|
32
32
|
}
|
33
33
|
|
34
34
|
|
35
|
-
|
35
|
+
static void ZSTD_rescaleFreqs(optState_t* optPtr, const BYTE* src, size_t srcSize)
|
36
36
|
{
|
37
37
|
unsigned u;
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
optPtr->cachedLiterals = NULL;
|
40
|
+
optPtr->cachedPrice = optPtr->cachedLitLength = 0;
|
41
|
+
optPtr->staticPrices = 0;
|
42
42
|
|
43
|
-
if (
|
44
|
-
if (srcSize <= 1024)
|
43
|
+
if (optPtr->litLengthSum == 0) {
|
44
|
+
if (srcSize <= 1024) optPtr->staticPrices = 1;
|
45
45
|
|
46
|
-
assert(
|
46
|
+
assert(optPtr->litFreq!=NULL);
|
47
47
|
for (u=0; u<=MaxLit; u++)
|
48
|
-
|
48
|
+
optPtr->litFreq[u] = 0;
|
49
49
|
for (u=0; u<srcSize; u++)
|
50
|
-
|
50
|
+
optPtr->litFreq[src[u]]++;
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
optPtr->litSum = 0;
|
53
|
+
optPtr->litLengthSum = MaxLL+1;
|
54
|
+
optPtr->matchLengthSum = MaxML+1;
|
55
|
+
optPtr->offCodeSum = (MaxOff+1);
|
56
|
+
optPtr->matchSum = (ZSTD_LITFREQ_ADD<<Litbits);
|
57
57
|
|
58
58
|
for (u=0; u<=MaxLit; u++) {
|
59
|
-
|
60
|
-
|
59
|
+
optPtr->litFreq[u] = 1 + (optPtr->litFreq[u]>>ZSTD_FREQ_DIV);
|
60
|
+
optPtr->litSum += optPtr->litFreq[u];
|
61
61
|
}
|
62
62
|
for (u=0; u<=MaxLL; u++)
|
63
|
-
|
63
|
+
optPtr->litLengthFreq[u] = 1;
|
64
64
|
for (u=0; u<=MaxML; u++)
|
65
|
-
|
65
|
+
optPtr->matchLengthFreq[u] = 1;
|
66
66
|
for (u=0; u<=MaxOff; u++)
|
67
|
-
|
67
|
+
optPtr->offCodeFreq[u] = 1;
|
68
68
|
} else {
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
optPtr->matchLengthSum = 0;
|
70
|
+
optPtr->litLengthSum = 0;
|
71
|
+
optPtr->offCodeSum = 0;
|
72
|
+
optPtr->matchSum = 0;
|
73
|
+
optPtr->litSum = 0;
|
74
74
|
|
75
75
|
for (u=0; u<=MaxLit; u++) {
|
76
|
-
|
77
|
-
|
76
|
+
optPtr->litFreq[u] = 1 + (optPtr->litFreq[u]>>(ZSTD_FREQ_DIV+1));
|
77
|
+
optPtr->litSum += optPtr->litFreq[u];
|
78
78
|
}
|
79
79
|
for (u=0; u<=MaxLL; u++) {
|
80
|
-
|
81
|
-
|
80
|
+
optPtr->litLengthFreq[u] = 1 + (optPtr->litLengthFreq[u]>>(ZSTD_FREQ_DIV+1));
|
81
|
+
optPtr->litLengthSum += optPtr->litLengthFreq[u];
|
82
82
|
}
|
83
83
|
for (u=0; u<=MaxML; u++) {
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
optPtr->matchLengthFreq[u] = 1 + (optPtr->matchLengthFreq[u]>>ZSTD_FREQ_DIV);
|
85
|
+
optPtr->matchLengthSum += optPtr->matchLengthFreq[u];
|
86
|
+
optPtr->matchSum += optPtr->matchLengthFreq[u] * (u + 3);
|
87
87
|
}
|
88
|
-
|
88
|
+
optPtr->matchSum *= ZSTD_LITFREQ_ADD;
|
89
89
|
for (u=0; u<=MaxOff; u++) {
|
90
|
-
|
91
|
-
|
90
|
+
optPtr->offCodeFreq[u] = 1 + (optPtr->offCodeFreq[u]>>ZSTD_FREQ_DIV);
|
91
|
+
optPtr->offCodeSum += optPtr->offCodeFreq[u];
|
92
92
|
}
|
93
93
|
}
|
94
94
|
|
95
|
-
ZSTD_setLog2Prices(
|
95
|
+
ZSTD_setLog2Prices(optPtr);
|
96
96
|
}
|
97
97
|
|
98
98
|
|
99
|
-
|
99
|
+
static U32 ZSTD_getLiteralPrice(optState_t* optPtr, U32 litLength, const BYTE* literals)
|
100
100
|
{
|
101
101
|
U32 price, u;
|
102
102
|
|
103
|
-
if (
|
103
|
+
if (optPtr->staticPrices)
|
104
104
|
return ZSTD_highbit32((U32)litLength+1) + (litLength*6);
|
105
105
|
|
106
106
|
if (litLength == 0)
|
107
|
-
return
|
107
|
+
return optPtr->log2litLengthSum - ZSTD_highbit32(optPtr->litLengthFreq[0]+1);
|
108
108
|
|
109
109
|
/* literals */
|
110
|
-
if (
|
111
|
-
U32 const additional = litLength -
|
112
|
-
const BYTE* literals2 =
|
113
|
-
price =
|
110
|
+
if (optPtr->cachedLiterals == literals) {
|
111
|
+
U32 const additional = litLength - optPtr->cachedLitLength;
|
112
|
+
const BYTE* literals2 = optPtr->cachedLiterals + optPtr->cachedLitLength;
|
113
|
+
price = optPtr->cachedPrice + additional * optPtr->log2litSum;
|
114
114
|
for (u=0; u < additional; u++)
|
115
|
-
price -= ZSTD_highbit32(
|
116
|
-
|
117
|
-
|
115
|
+
price -= ZSTD_highbit32(optPtr->litFreq[literals2[u]]+1);
|
116
|
+
optPtr->cachedPrice = price;
|
117
|
+
optPtr->cachedLitLength = litLength;
|
118
118
|
} else {
|
119
|
-
price = litLength *
|
119
|
+
price = litLength * optPtr->log2litSum;
|
120
120
|
for (u=0; u < litLength; u++)
|
121
|
-
price -= ZSTD_highbit32(
|
121
|
+
price -= ZSTD_highbit32(optPtr->litFreq[literals[u]]+1);
|
122
122
|
|
123
123
|
if (litLength >= 12) {
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
optPtr->cachedLiterals = literals;
|
125
|
+
optPtr->cachedPrice = price;
|
126
|
+
optPtr->cachedLitLength = litLength;
|
127
127
|
}
|
128
128
|
}
|
129
129
|
|
130
130
|
/* literal Length */
|
131
131
|
{ const BYTE LL_deltaCode = 19;
|
132
132
|
const BYTE llCode = (litLength>63) ? (BYTE)ZSTD_highbit32(litLength) + LL_deltaCode : LL_Code[litLength];
|
133
|
-
price += LL_bits[llCode] +
|
133
|
+
price += LL_bits[llCode] + optPtr->log2litLengthSum - ZSTD_highbit32(optPtr->litLengthFreq[llCode]+1);
|
134
134
|
}
|
135
135
|
|
136
136
|
return price;
|
137
137
|
}
|
138
138
|
|
139
139
|
|
140
|
-
|
140
|
+
FORCE_INLINE_TEMPLATE U32 ZSTD_getPrice(optState_t* optPtr, U32 litLength, const BYTE* literals, U32 offset, U32 matchLength, const int ultra)
|
141
141
|
{
|
142
142
|
/* offset */
|
143
143
|
U32 price;
|
144
144
|
BYTE const offCode = (BYTE)ZSTD_highbit32(offset+1);
|
145
145
|
|
146
|
-
if (
|
147
|
-
return ZSTD_getLiteralPrice(
|
146
|
+
if (optPtr->staticPrices)
|
147
|
+
return ZSTD_getLiteralPrice(optPtr, litLength, literals) + ZSTD_highbit32((U32)matchLength+1) + 16 + offCode;
|
148
148
|
|
149
|
-
price = offCode +
|
149
|
+
price = offCode + optPtr->log2offCodeSum - ZSTD_highbit32(optPtr->offCodeFreq[offCode]+1);
|
150
150
|
if (!ultra && offCode >= 20) price += (offCode-19)*2;
|
151
151
|
|
152
152
|
/* match Length */
|
153
153
|
{ const BYTE ML_deltaCode = 36;
|
154
154
|
const BYTE mlCode = (matchLength>127) ? (BYTE)ZSTD_highbit32(matchLength) + ML_deltaCode : ML_Code[matchLength];
|
155
|
-
price += ML_bits[mlCode] +
|
155
|
+
price += ML_bits[mlCode] + optPtr->log2matchLengthSum - ZSTD_highbit32(optPtr->matchLengthFreq[mlCode]+1);
|
156
156
|
}
|
157
157
|
|
158
|
-
return price + ZSTD_getLiteralPrice(
|
158
|
+
return price + ZSTD_getLiteralPrice(optPtr, litLength, literals) + optPtr->factor;
|
159
159
|
}
|
160
160
|
|
161
161
|
|
162
|
-
|
162
|
+
static void ZSTD_updatePrice(optState_t* optPtr, U32 litLength, const BYTE* literals, U32 offset, U32 matchLength)
|
163
163
|
{
|
164
164
|
U32 u;
|
165
165
|
|
166
166
|
/* literals */
|
167
|
-
|
167
|
+
optPtr->litSum += litLength*ZSTD_LITFREQ_ADD;
|
168
168
|
for (u=0; u < litLength; u++)
|
169
|
-
|
169
|
+
optPtr->litFreq[literals[u]] += ZSTD_LITFREQ_ADD;
|
170
170
|
|
171
171
|
/* literal Length */
|
172
172
|
{ const BYTE LL_deltaCode = 19;
|
173
173
|
const BYTE llCode = (litLength>63) ? (BYTE)ZSTD_highbit32(litLength) + LL_deltaCode : LL_Code[litLength];
|
174
|
-
|
175
|
-
|
174
|
+
optPtr->litLengthFreq[llCode]++;
|
175
|
+
optPtr->litLengthSum++;
|
176
176
|
}
|
177
177
|
|
178
178
|
/* match offset */
|
179
179
|
{ BYTE const offCode = (BYTE)ZSTD_highbit32(offset+1);
|
180
|
-
|
181
|
-
|
180
|
+
optPtr->offCodeSum++;
|
181
|
+
optPtr->offCodeFreq[offCode]++;
|
182
182
|
}
|
183
183
|
|
184
184
|
/* match Length */
|
185
185
|
{ const BYTE ML_deltaCode = 36;
|
186
186
|
const BYTE mlCode = (matchLength>127) ? (BYTE)ZSTD_highbit32(matchLength) + ML_deltaCode : ML_Code[matchLength];
|
187
|
-
|
188
|
-
|
187
|
+
optPtr->matchLengthFreq[mlCode]++;
|
188
|
+
optPtr->matchLengthSum++;
|
189
189
|
}
|
190
190
|
|
191
|
-
ZSTD_setLog2Prices(
|
191
|
+
ZSTD_setLog2Prices(optPtr);
|
192
192
|
}
|
193
193
|
|
194
194
|
|
@@ -203,7 +203,7 @@ MEM_STATIC void ZSTD_updatePrice(seqStore_t* seqStorePtr, U32 litLength, const B
|
|
203
203
|
|
204
204
|
|
205
205
|
/* function safe only for comparisons */
|
206
|
-
|
206
|
+
static U32 ZSTD_readMINMATCH(const void* memPtr, U32 length)
|
207
207
|
{
|
208
208
|
switch (length)
|
209
209
|
{
|
@@ -219,7 +219,7 @@ MEM_STATIC U32 ZSTD_readMINMATCH(const void* memPtr, U32 length)
|
|
219
219
|
|
220
220
|
/* Update hashTable3 up to ip (excluded)
|
221
221
|
Assumption : always within prefix (i.e. not within extDict) */
|
222
|
-
|
222
|
+
static
|
223
223
|
U32 ZSTD_insertAndFindFirstIndexHash3 (ZSTD_CCtx* zc, const BYTE* ip)
|
224
224
|
{
|
225
225
|
U32* const hashTable3 = zc->hashTable3;
|
@@ -412,11 +412,12 @@ static U32 ZSTD_BtGetAllMatches_selectMLS_extDict (
|
|
412
412
|
/*-*******************************
|
413
413
|
* Optimal parser
|
414
414
|
*********************************/
|
415
|
-
|
415
|
+
FORCE_INLINE_TEMPLATE
|
416
416
|
void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
|
417
417
|
const void* src, size_t srcSize, const int ultra)
|
418
418
|
{
|
419
419
|
seqStore_t* seqStorePtr = &(ctx->seqStore);
|
420
|
+
optState_t* optStatePtr = &(ctx->optState);
|
420
421
|
const BYTE* const istart = (const BYTE*)src;
|
421
422
|
const BYTE* ip = istart;
|
422
423
|
const BYTE* anchor = istart;
|
@@ -430,16 +431,16 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
|
|
430
431
|
const U32 mls = ctx->appliedParams.cParams.searchLength;
|
431
432
|
const U32 minMatch = (ctx->appliedParams.cParams.searchLength == 3) ? 3 : 4;
|
432
433
|
|
433
|
-
ZSTD_optimal_t* opt =
|
434
|
-
ZSTD_match_t* matches =
|
434
|
+
ZSTD_optimal_t* opt = optStatePtr->priceTable;
|
435
|
+
ZSTD_match_t* matches = optStatePtr->matchTable;
|
435
436
|
const BYTE* inr;
|
436
437
|
U32 offset, rep[ZSTD_REP_NUM];
|
437
438
|
|
438
439
|
/* init */
|
439
440
|
ctx->nextToUpdate3 = ctx->nextToUpdate;
|
440
|
-
ZSTD_rescaleFreqs(
|
441
|
+
ZSTD_rescaleFreqs(optStatePtr, (const BYTE*)src, srcSize);
|
441
442
|
ip += (ip==prefixStart);
|
442
|
-
{ U32 i; for (i=0; i<ZSTD_REP_NUM; i++) rep[i]=
|
443
|
+
{ U32 i; for (i=0; i<ZSTD_REP_NUM; i++) rep[i]=seqStorePtr->rep[i]; }
|
443
444
|
|
444
445
|
/* Match Loop */
|
445
446
|
while (ip < ilimit) {
|
@@ -462,7 +463,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
|
|
462
463
|
}
|
463
464
|
best_off = i - (ip == anchor);
|
464
465
|
do {
|
465
|
-
price = ZSTD_getPrice(
|
466
|
+
price = ZSTD_getPrice(optStatePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
|
466
467
|
if (mlen > last_pos || price < opt[mlen].price)
|
467
468
|
SET_PRICE(mlen, mlen, i, litlen, price); /* note : macro modifies last_pos */
|
468
469
|
mlen--;
|
@@ -487,7 +488,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
|
|
487
488
|
mlen = (u>0) ? matches[u-1].len+1 : best_mlen;
|
488
489
|
best_mlen = matches[u].len;
|
489
490
|
while (mlen <= best_mlen) {
|
490
|
-
price = ZSTD_getPrice(
|
491
|
+
price = ZSTD_getPrice(optStatePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
|
491
492
|
if (mlen > last_pos || price < opt[mlen].price)
|
492
493
|
SET_PRICE(mlen, mlen, matches[u].off, litlen, price); /* note : macro modifies last_pos */
|
493
494
|
mlen++;
|
@@ -507,12 +508,12 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
|
|
507
508
|
if (opt[cur-1].mlen == 1) {
|
508
509
|
litlen = opt[cur-1].litlen + 1;
|
509
510
|
if (cur > litlen) {
|
510
|
-
price = opt[cur - litlen].price + ZSTD_getLiteralPrice(
|
511
|
+
price = opt[cur - litlen].price + ZSTD_getLiteralPrice(optStatePtr, litlen, inr-litlen);
|
511
512
|
} else
|
512
|
-
price = ZSTD_getLiteralPrice(
|
513
|
+
price = ZSTD_getLiteralPrice(optStatePtr, litlen, anchor);
|
513
514
|
} else {
|
514
515
|
litlen = 1;
|
515
|
-
price = opt[cur - 1].price + ZSTD_getLiteralPrice(
|
516
|
+
price = opt[cur - 1].price + ZSTD_getLiteralPrice(optStatePtr, litlen, inr-1);
|
516
517
|
}
|
517
518
|
|
518
519
|
if (cur > last_pos || price <= opt[cur].price)
|
@@ -554,12 +555,12 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
|
|
554
555
|
if (opt[cur].mlen == 1) {
|
555
556
|
litlen = opt[cur].litlen;
|
556
557
|
if (cur > litlen) {
|
557
|
-
price = opt[cur - litlen].price + ZSTD_getPrice(
|
558
|
+
price = opt[cur - litlen].price + ZSTD_getPrice(optStatePtr, litlen, inr-litlen, best_off, mlen - MINMATCH, ultra);
|
558
559
|
} else
|
559
|
-
price = ZSTD_getPrice(
|
560
|
+
price = ZSTD_getPrice(optStatePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
|
560
561
|
} else {
|
561
562
|
litlen = 0;
|
562
|
-
price = opt[cur].price + ZSTD_getPrice(
|
563
|
+
price = opt[cur].price + ZSTD_getPrice(optStatePtr, 0, NULL, best_off, mlen - MINMATCH, ultra);
|
563
564
|
}
|
564
565
|
|
565
566
|
if (cur + mlen > last_pos || price <= opt[cur + mlen].price)
|
@@ -586,12 +587,12 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
|
|
586
587
|
if (opt[cur].mlen == 1) {
|
587
588
|
litlen = opt[cur].litlen;
|
588
589
|
if (cur > litlen)
|
589
|
-
price = opt[cur - litlen].price + ZSTD_getPrice(
|
590
|
+
price = opt[cur - litlen].price + ZSTD_getPrice(optStatePtr, litlen, ip+cur-litlen, matches[u].off-1, mlen - MINMATCH, ultra);
|
590
591
|
else
|
591
|
-
price = ZSTD_getPrice(
|
592
|
+
price = ZSTD_getPrice(optStatePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
|
592
593
|
} else {
|
593
594
|
litlen = 0;
|
594
|
-
price = opt[cur].price + ZSTD_getPrice(
|
595
|
+
price = opt[cur].price + ZSTD_getPrice(optStatePtr, 0, NULL, matches[u].off-1, mlen - MINMATCH, ultra);
|
595
596
|
}
|
596
597
|
|
597
598
|
if (cur + mlen > last_pos || (price < opt[cur + mlen].price))
|
@@ -645,13 +646,13 @@ _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */
|
|
645
646
|
if (litLength==0) offset--;
|
646
647
|
}
|
647
648
|
|
648
|
-
ZSTD_updatePrice(
|
649
|
+
ZSTD_updatePrice(optStatePtr, litLength, anchor, offset, mlen-MINMATCH);
|
649
650
|
ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, mlen-MINMATCH);
|
650
651
|
anchor = ip = ip + mlen;
|
651
652
|
} } /* for (cur=0; cur < last_pos; ) */
|
652
653
|
|
653
654
|
/* Save reps for next block */
|
654
|
-
{ int i; for (i=0; i<ZSTD_REP_NUM; i++)
|
655
|
+
{ int i; for (i=0; i<ZSTD_REP_NUM; i++) seqStorePtr->repToConfirm[i] = rep[i]; }
|
655
656
|
|
656
657
|
/* Last Literals */
|
657
658
|
{ size_t const lastLLSize = iend - anchor;
|
@@ -661,11 +662,12 @@ _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */
|
|
661
662
|
}
|
662
663
|
|
663
664
|
|
664
|
-
|
665
|
+
FORCE_INLINE_TEMPLATE
|
665
666
|
void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
|
666
667
|
const void* src, size_t srcSize, const int ultra)
|
667
668
|
{
|
668
669
|
seqStore_t* seqStorePtr = &(ctx->seqStore);
|
670
|
+
optState_t* optStatePtr = &(ctx->optState);
|
669
671
|
const BYTE* const istart = (const BYTE*)src;
|
670
672
|
const BYTE* ip = istart;
|
671
673
|
const BYTE* anchor = istart;
|
@@ -683,16 +685,16 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
|
|
683
685
|
const U32 mls = ctx->appliedParams.cParams.searchLength;
|
684
686
|
const U32 minMatch = (ctx->appliedParams.cParams.searchLength == 3) ? 3 : 4;
|
685
687
|
|
686
|
-
ZSTD_optimal_t* opt =
|
687
|
-
ZSTD_match_t* matches =
|
688
|
+
ZSTD_optimal_t* opt = optStatePtr->priceTable;
|
689
|
+
ZSTD_match_t* matches = optStatePtr->matchTable;
|
688
690
|
const BYTE* inr;
|
689
691
|
|
690
692
|
/* init */
|
691
693
|
U32 offset, rep[ZSTD_REP_NUM];
|
692
|
-
{ U32 i; for (i=0; i<ZSTD_REP_NUM; i++) rep[i]=
|
694
|
+
{ U32 i; for (i=0; i<ZSTD_REP_NUM; i++) rep[i]=seqStorePtr->rep[i]; }
|
693
695
|
|
694
696
|
ctx->nextToUpdate3 = ctx->nextToUpdate;
|
695
|
-
ZSTD_rescaleFreqs(
|
697
|
+
ZSTD_rescaleFreqs(optStatePtr, (const BYTE*)src, srcSize);
|
696
698
|
ip += (ip==prefixStart);
|
697
699
|
|
698
700
|
/* Match Loop */
|
@@ -726,7 +728,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
|
|
726
728
|
best_off = i - (ip==anchor);
|
727
729
|
litlen = opt[0].litlen;
|
728
730
|
do {
|
729
|
-
price = ZSTD_getPrice(
|
731
|
+
price = ZSTD_getPrice(optStatePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
|
730
732
|
if (mlen > last_pos || price < opt[mlen].price)
|
731
733
|
SET_PRICE(mlen, mlen, i, litlen, price); /* note : macro modifies last_pos */
|
732
734
|
mlen--;
|
@@ -756,7 +758,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
|
|
756
758
|
best_mlen = matches[u].len;
|
757
759
|
litlen = opt[0].litlen;
|
758
760
|
while (mlen <= best_mlen) {
|
759
|
-
price = ZSTD_getPrice(
|
761
|
+
price = ZSTD_getPrice(optStatePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
|
760
762
|
if (mlen > last_pos || price < opt[mlen].price)
|
761
763
|
SET_PRICE(mlen, mlen, matches[u].off, litlen, price);
|
762
764
|
mlen++;
|
@@ -773,12 +775,12 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
|
|
773
775
|
if (opt[cur-1].mlen == 1) {
|
774
776
|
litlen = opt[cur-1].litlen + 1;
|
775
777
|
if (cur > litlen) {
|
776
|
-
price = opt[cur - litlen].price + ZSTD_getLiteralPrice(
|
778
|
+
price = opt[cur - litlen].price + ZSTD_getLiteralPrice(optStatePtr, litlen, inr-litlen);
|
777
779
|
} else
|
778
|
-
price = ZSTD_getLiteralPrice(
|
780
|
+
price = ZSTD_getLiteralPrice(optStatePtr, litlen, anchor);
|
779
781
|
} else {
|
780
782
|
litlen = 1;
|
781
|
-
price = opt[cur - 1].price + ZSTD_getLiteralPrice(
|
783
|
+
price = opt[cur - 1].price + ZSTD_getLiteralPrice(optStatePtr, litlen, inr-1);
|
782
784
|
}
|
783
785
|
|
784
786
|
if (cur > last_pos || price <= opt[cur].price)
|
@@ -826,12 +828,12 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
|
|
826
828
|
if (opt[cur].mlen == 1) {
|
827
829
|
litlen = opt[cur].litlen;
|
828
830
|
if (cur > litlen) {
|
829
|
-
price = opt[cur - litlen].price + ZSTD_getPrice(
|
831
|
+
price = opt[cur - litlen].price + ZSTD_getPrice(optStatePtr, litlen, inr-litlen, best_off, mlen - MINMATCH, ultra);
|
830
832
|
} else
|
831
|
-
price = ZSTD_getPrice(
|
833
|
+
price = ZSTD_getPrice(optStatePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
|
832
834
|
} else {
|
833
835
|
litlen = 0;
|
834
|
-
price = opt[cur].price + ZSTD_getPrice(
|
836
|
+
price = opt[cur].price + ZSTD_getPrice(optStatePtr, 0, NULL, best_off, mlen - MINMATCH, ultra);
|
835
837
|
}
|
836
838
|
|
837
839
|
if (cur + mlen > last_pos || price <= opt[cur + mlen].price)
|
@@ -858,12 +860,12 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
|
|
858
860
|
if (opt[cur].mlen == 1) {
|
859
861
|
litlen = opt[cur].litlen;
|
860
862
|
if (cur > litlen)
|
861
|
-
price = opt[cur - litlen].price + ZSTD_getPrice(
|
863
|
+
price = opt[cur - litlen].price + ZSTD_getPrice(optStatePtr, litlen, ip+cur-litlen, matches[u].off-1, mlen - MINMATCH, ultra);
|
862
864
|
else
|
863
|
-
price = ZSTD_getPrice(
|
865
|
+
price = ZSTD_getPrice(optStatePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
|
864
866
|
} else {
|
865
867
|
litlen = 0;
|
866
|
-
price = opt[cur].price + ZSTD_getPrice(
|
868
|
+
price = opt[cur].price + ZSTD_getPrice(optStatePtr, 0, NULL, matches[u].off-1, mlen - MINMATCH, ultra);
|
867
869
|
}
|
868
870
|
|
869
871
|
if (cur + mlen > last_pos || (price < opt[cur + mlen].price))
|
@@ -918,13 +920,13 @@ _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */
|
|
918
920
|
if (litLength==0) offset--;
|
919
921
|
}
|
920
922
|
|
921
|
-
ZSTD_updatePrice(
|
923
|
+
ZSTD_updatePrice(optStatePtr, litLength, anchor, offset, mlen-MINMATCH);
|
922
924
|
ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, mlen-MINMATCH);
|
923
925
|
anchor = ip = ip + mlen;
|
924
926
|
} } /* for (cur=0; cur < last_pos; ) */
|
925
927
|
|
926
928
|
/* Save reps for next block */
|
927
|
-
{ int i; for (i=0; i<ZSTD_REP_NUM; i++)
|
929
|
+
{ int i; for (i=0; i<ZSTD_REP_NUM; i++) seqStorePtr->repToConfirm[i] = rep[i]; }
|
928
930
|
|
929
931
|
/* Last Literals */
|
930
932
|
{ size_t lastLLSize = iend - anchor;
|